Skip to content

Commit

Permalink
add CreateShorestRouteByPoints
Browse files Browse the repository at this point in the history
  • Loading branch information
chuongmep committed Apr 13, 2023
1 parent 12deada commit 1e71974
Show file tree
Hide file tree
Showing 4 changed files with 623 additions and 3 deletions.
13 changes: 13 additions & 0 deletions OpenMEP/ConnectorManager/Connector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,19 @@ public static double Radius(Autodesk.Revit.DB.Connector connector)
Autodesk.Revit.DB.Connector? connector = GetConnectorClosest(element2, connectorSet);
return connector;
}

/// <summary>
/// Get closest Connector inside the Element with a Point
/// </summary>
/// <param name="element">element contains connectors </param>
/// <param name="point">point need to check</param>
/// <returns name="Connector">closest connector with point</returns>
public static Autodesk.Revit.DB.Connector? GetConnectorClosest(global::Revit.Elements.Element? element,
Autodesk.DesignScript.Geometry.Point point)
{
List<Autodesk.Revit.DB.Connector?> connectors = GetConnectors(element);
return GetConnectorClosest(point, connectors);
}

/// <summary>
/// return connector set of element
Expand Down
43 changes: 40 additions & 3 deletions OpenMEP/Element/Pipe.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
using Autodesk.Revit.DB.Plumbing;
using Dynamo.Graph.Nodes;
using OpenMEP.Helpers;
using OpenMEPSandbox.Algo;
using Revit.GeometryConversion;
using RevitServices.Persistence;
using RevitServices.Transactions;
using Point = OpenMEPSandbox.Geometry.Point;

namespace OpenMEP.Element;

/// <summary>A pipe in the Autodesk Revit MEP product.</summary>
/// <remarks>The pipe is only available in the Autodesk Revit MEP product.</remarks>
public class Pipe
Expand Down Expand Up @@ -164,6 +166,40 @@ private Pipe()
return newPipe;
}

/// <summary>
/// Create pipe shortest route by the list points use TravellingSalesman algorithm
/// </summary>
/// <param name="systemType">system type of pipe</param>
/// <param name="pipeType">type of pipe</param>
/// <param name="level">level of pipe</param>
/// <param name="points">list point ordered of pipe</param>
/// <param name="diameter">value diameter for create pipe</param>
/// <returns name="elements">the elements include new pipe and new elbow of route</returns>
/// <example>
/// ![](../OpenMEPPage/element/dyn/pic/Pipe.CreateRouteShortestByPoints.png)
/// [](../OpenMEPPage/element/dyn/Pipe.CreateRouteShortestByPoints.dyn)
/// </example>
[NodeSearchTags("create", "pipe", "network", "list", "route")]
[NodeCategory("Create")]
public static List<global::Revit.Elements.Element?> CreateRouteShortestByPoints(global::Revit.Elements.Element systemType,
global::Revit.Elements.Element pipeType,
global::Revit.Elements.Element level, List<Autodesk.DesignScript.Geometry.Point> points, double diameter)
{
List<global::Revit.Elements.Element?> elements = new List<global::Revit.Elements.Element?>();
if (points.Count == 0) throw new Exception("List point is empty");
if (points.Count == 1) throw new Exception("List point is not enough to create a route");
var routePoints = TravellingSalesman.FindShortestRoute(points);
for (int i = 0; i < routePoints.Count - 1; i++)
{
Autodesk.DesignScript.Geometry.Point startPoint = routePoints[i];
Autodesk.DesignScript.Geometry.Point endPoint = routePoints[i + 1];
var newPipe = CreateByTwoPoint(systemType, pipeType, level, startPoint, endPoint);
SetDiameter(newPipe, diameter);
elements.Add(newPipe);
}
return elements;
}

/// <summary>
/// create new pipe by direction and length
/// </summary>
Expand All @@ -182,7 +218,7 @@ private Pipe()
public static global::Revit.Elements.Element? CreateByPointAndDirection(global::Revit.Elements.Element systemType,
global::Revit.Elements.Element pipeType,
global::Revit.Elements.Element level, Autodesk.DesignScript.Geometry.Point startPoint,
Autodesk.DesignScript.Geometry.Vector direction,double length, double diameter)
Autodesk.DesignScript.Geometry.Vector direction, double length, double diameter)
{
var endPoint = Point.Offset(startPoint, length, direction);
Revit.Elements.Element? pipe = CreateByTwoPoint(systemType, pipeType, level, startPoint, endPoint);
Expand Down Expand Up @@ -289,7 +325,7 @@ Autodesk.DesignScript.Geometry.Point point
TransactionManager.Instance.TransactionTaskDone();
return pipe;
}


/// <summary>
/// return information diameter of pipe
Expand Down Expand Up @@ -546,7 +582,8 @@ Autodesk.DesignScript.Geometry.Point point
/// ![](../OpenMEPPage/element/dyn/pic/Pipe.GetFamilySymbolMechanicalJointsByRouting.png)
/// </example>
[MultiReturn("FamilySymbol", "Family")]
public static Dictionary<string,object?> GetFamilySymbolMechanicalJointsByRouting(global::Revit.Elements.Element? pipe)
public static Dictionary<string, object?> GetFamilySymbolMechanicalJointsByRouting(
global::Revit.Elements.Element? pipe)
{
double radius = ConnectorManager.Connector.GetConnectors(pipe).Select(x => x!.Radius).FirstOrDefault();
Autodesk.Revit.DB.Document doc = DocumentManager.Instance.CurrentDBDocument;
Expand Down
Loading

0 comments on commit 1e71974

Please sign in to comment.