Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
chuongmep committed Mar 16, 2023
2 parents 3420efe + ee69413 commit bd87ead
Show file tree
Hide file tree
Showing 9 changed files with 1,063 additions and 5 deletions.
92 changes: 90 additions & 2 deletions OpenMEP/ConnectorManager/Connector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,34 @@ public static double Radius(Autodesk.Revit.DB.Connector connector)
if (connectorManager == null) throw new ArgumentNullException(nameof(connectorManager));
return connectorManager.UnusedConnectors.Cast<Autodesk.Revit.DB.Connector>().ToList()!;
}

/// <summary>
/// return all connectors of element except connector same id with connector input
/// </summary>
/// <param name="element">the element</param>
/// <param name="connector">connector</param>
/// <returns name="connectors">list of connectors</returns>
/// <example>
/// ![](../OpenMEPPage/connectormanager/dyn/pic/Connector.GetRemainingConnector.png)
/// </example>
public static List<Autodesk.Revit.DB.Connector?> GetRemainingConnector(Revit.Elements.Element? element ,Autodesk.Revit.DB.Connector connector)
{
return GetConnectors(element).Where(c => c!.Id != connector.Id).ToList();
}

/// <summary>
/// return all connectors of list connectors except connector same id with connector input
/// </summary>
/// <param name="connectors">list connectors need to check</param>
/// <param name="connector">connector need to remove</param>
/// <returns name="connectors">list of connectors</returns>
/// <example>
/// ![](../OpenMEPPage/connectormanager/dyn/pic/Connector.GetRemainingConnector2.png)
/// </example>
public static List<Autodesk.Revit.DB.Connector> GetRemainingConnector(List<Autodesk.Revit.DB.Connector> connectors,Autodesk.Revit.DB.Connector connector)
{
return connectors.Where(c => c!.Id != connector.Id).ToList();
}

/// <summary>
/// return system type of connector
Expand Down Expand Up @@ -711,7 +739,7 @@ public static double AssignedKCoefficient(Autodesk.Revit.DB.Connector connector)
/// <example>
/// ![](../OpenMEPPage/connectormanager/dyn/pic/Connector.GetElementConnectedWith.png)
/// </example>
public static Revit.Elements.Element? GetElementConnectedWith(Autodesk.Revit.DB.Connector connector)
public static Revit.Elements.Element? GetElementConnectedWith(Autodesk.Revit.DB.Connector? connector)
{
if (connector == null) throw new ArgumentNullException(nameof(connector));
if (connector.IsConnected)
Expand All @@ -724,7 +752,67 @@ public static double AssignedKCoefficient(Autodesk.Revit.DB.Connector connector)

return null;
}


/// <summary>
/// Return All Element Connected Continuous In Branch
/// Be careful, because this node require recursive to check all connected.
/// </summary>
/// <param name="element">element</param>
/// <returns name="elements">list element connected Continuous from element</returns>
/// <example>
/// ![](../OpenMEPPage/connectormanager/dyn/pic/Connector.GetElementConnectedContinuous.png)
/// </example>
public static List<Revit.Elements.Element> GetElementConnectedContinuous(Revit.Elements.Element? element)
{
if (element == null) throw new ArgumentNullException(nameof(element));
Dictionary<string, Revit.Elements.Element> OutElements =
new Dictionary<string, Revit.Elements.Element>();
List<Revit.Elements.Element> collector = Collector(element, OutElements);
return collector;
}
/// <summary>
/// Return All Element Connected Continuous In Branch
/// Be careful, because this node require recursive to check all connected.
/// </summary>
/// <param name="connector">element</param>
/// <returns name="elements">list element connected Continuous from element</returns>
/// <example>
/// ![](../OpenMEPPage/connectormanager/dyn/pic/Connector.GetElementConnectedContinuous.png)
/// </example>
public static List<Revit.Elements.Element> GetElementConnectedContinuous(Autodesk.Revit.DB.Connector connector)
{
if (connector == null) throw new ArgumentNullException(nameof(connector));
Dictionary<string, Revit.Elements.Element> OutElements =
new Dictionary<string, Revit.Elements.Element>();
List<Revit.Elements.Element> collector = Collector(connector.Owner.ToDynamoType(), OutElements);
return collector;
}
//recursive element from e to end branch side by side other
private static List<Revit.Elements.Element> Collector(Revit.Elements.Element? e,
Dictionary<string, Revit.Elements.Element> OutElements)
{
double count = 0;
List<Revit.Elements.Element?> elements = GetConnectors(e).Select(GetElementConnectedWith).ToList();
foreach (var item in elements)
{
if(item==null) continue;
if (OutElements.ContainsKey(item.Id.ToString()))
{
count += 1;
}
else
{
OutElements[item.Id.ToString()] = item;
Collector(item, OutElements);
}
}
if (System.Math.Abs(count - elements.Count) < 0.0001)
{
return new List<Revit.Elements.Element>(OutElements.Values);
}
return new List<Revit.Elements.Element>(OutElements.Values);
}

/// <summary>
/// return element connected with connector
/// </summary>
Expand Down
48 changes: 48 additions & 0 deletions OpenMEP/Element/Element.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,54 @@ private Element()
return element;
}

/// <summary>
/// Set Rotate of fitting
/// </summary>
/// <param name="element">the element</param>
/// <param name="Axis">Line Axis</param>
/// <param name="angle">angle to rotate(Degrees)</param>
/// <returns name="fitting">family instance</returns>
[NodeCategory("Action")]
public static global::Revit.Elements.Element Rotate(global::Revit.Elements.Element element,
Autodesk.DesignScript.Geometry.Line Axis,
double angle)
{
TransactionManager.Instance.ForceCloseTransaction();
Autodesk.Revit.DB.Document doc = DocumentManager.Instance.CurrentDBDocument;
TransactionManager.Instance.EnsureInTransaction(doc);
double degree2Radian = angle * Math.PI / 180;
ElementTransformUtils.RotateElement(doc, element.InternalElement.Id,
(Autodesk.Revit.DB.Line) Axis.ToRevitType(), degree2Radian);
TransactionManager.Instance.TransactionTaskDone();
return element;
}

/// <summary>
/// Set Rotate of fitting
/// </summary>
/// <param name="element">the element</param>
/// <param name="Axis">Direction Axis</param>
/// <param name="angle">angle to rotate(Degrees)</param>
/// <returns name="fitting">family instance</returns>
[NodeCategory("Action")]
public static global::Revit.Elements.Element Rotate(global::Revit.Elements.Element element,
Autodesk.DesignScript.Geometry.Vector Axis,
double angle)
{
TransactionManager.Instance.ForceCloseTransaction();
Autodesk.Revit.DB.Document doc = DocumentManager.Instance.CurrentDBDocument;
TransactionManager.Instance.EnsureInTransaction(doc);
double degree2Radian = angle * Math.PI / 180;
LocationPoint? locationPoint = element.InternalElement.Location as LocationPoint;
var location = locationPoint?.Point;
Autodesk.Revit.DB.Line line =
Autodesk.Revit.DB.Line.CreateBound(location!.Add(Axis.ToRevitType().Multiply(2)), location);
ElementTransformUtils.RotateElement(doc, element.InternalElement.Id,
(Autodesk.Revit.DB.Line) line, degree2Radian);
TransactionManager.Instance.TransactionTaskDone();
return element;
}

/// <summary>
/// Return Level Of Element
/// </summary>
Expand Down
10 changes: 7 additions & 3 deletions OpenMEP/Element/FamilyInstance.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
using Autodesk.DesignScript.Runtime;
using Autodesk.Revit.DB;
using Dynamo.Graph.Nodes;
using OpenMEPSandbox.Geometry;
using Revit.GeometryConversion;
using RevitServices.Persistence;
using RevitServices.Transactions;

namespace OpenMEP.Element;

public class FamilyInstance
{
private FamilyInstance()
{

}
/// <summary>
/// Retrieves the MEP model for the family instance.</summary>
Expand All @@ -26,6 +28,7 @@ private FamilyInstance()
{
return fam.MEPModel;
}

return null;
}

Expand All @@ -43,9 +46,10 @@ private FamilyInstance()
/// <returns name="YZPlane">Plane</returns>
/// <returns name="ZXPlane">Plane</returns>
[MultiReturn(new[] {"Display", "Origin", "XAxis", "YAxis", "ZAxis", "XYPlane", "YZPlane", "ZXPlane"})]
public static Dictionary<string, object?> Display(Revit.Elements.Element familyInstance,double length=1000)
public static Dictionary<string, object?> Display(Revit.Elements.Element familyInstance, double length = 1000)
{
Autodesk.Revit.DB.FamilyInstance? internalElement = familyInstance.InternalElement as Autodesk.Revit.DB.FamilyInstance;
Autodesk.Revit.DB.FamilyInstance? internalElement =
familyInstance.InternalElement as Autodesk.Revit.DB.FamilyInstance;
if (internalElement == null) throw new ArgumentNullException(nameof(familyInstance));
Transform transform = internalElement.GetTotalTransform();
return CoordinateSystem.Display(transform.ToCoordinateSystem(), length);
Expand Down
Loading

0 comments on commit bd87ead

Please sign in to comment.