Skip to content

Commit

Permalink
Add Tee Fitting By Two MEPCurve
Browse files Browse the repository at this point in the history
  • Loading branch information
chuongmep committed Mar 18, 2023
1 parent 29e3e3d commit 743a050
Show file tree
Hide file tree
Showing 7 changed files with 349 additions and 85 deletions.
4 changes: 2 additions & 2 deletions OpenMEP/Element/Fitting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ private Fitting()
/// <returns name="familyinstance">If creation was successful then an family instance to the new object is returned, and the transition fitting will be added at the connectors' end if necessary, otherwise an exception with failure information will be thrown</returns>
[NodeCategory("Create")]
public static global::Revit.Elements.Element? NewTeeFitting(Autodesk.Revit.DB.Connector connector1,
Autodesk.Revit.DB.Connector connector2,
Autodesk.Revit.DB.Connector connector3)
Connector? connector2,
Connector? connector3)
{
Autodesk.Revit.DB.Document doc = DocumentManager.Instance.CurrentDBDocument;
TransactionManager.Instance.EnsureInTransaction(doc);
Expand Down
68 changes: 66 additions & 2 deletions OpenMEP/Element/MEPCurve.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using GShark.Geometry;
using OpenMEP.Helpers;
using Revit.GeometryConversion;
using RevitServices.Persistence;
using RevitServices.Transactions;
using Curve = Autodesk.DesignScript.Geometry.Curve;
using Line = Autodesk.Revit.DB.Line;
Expand Down Expand Up @@ -229,8 +230,71 @@ private static void AdjustMepCurve(Autodesk.Revit.DB.Element mepCurve, XYZ p1, X
return newTeeFitting.ToDynamoType();
}



/// <summary>
/// Create a new tee fitting 90 degrees by two mep curve
/// </summary>
/// <param name="MepCurve1">the first element mep curve</param>
/// <param name="MepCurve2">the second element mep curve</param>
/// <returns name="familyinstance">the element family instance</returns>
/// <example>
/// ![](../OpenMEPPage/element/dyn/pic/MEPCurve.NewTeeFitting2.png)
/// </example>
public static Revit.Elements.Element? NewTeeFitting(Revit.Elements.Element MepCurve1,
Revit.Elements.Element MepCurve2)
{
if(MepCurve1==null) throw new ArgumentNullException(nameof(MepCurve1));
if(MepCurve2==null) throw new ArgumentNullException(nameof(MepCurve2));
//review is perpendicular
Autodesk.Revit.DB.Element e1 = MepCurve1.InternalElement;
LocationCurve? lc1 = e1.Location as LocationCurve;
Autodesk.Revit.DB.Curve curve1 = lc1!.Curve;
Autodesk.Revit.DB.Element e2 = MepCurve2.InternalElement;
LocationCurve? lc2 = e2.Location as LocationCurve;
Autodesk.Revit.DB.Curve curve2 = lc2!.Curve;
Autodesk.Revit.DB.XYZ vector = curve1.GetEndPoint(1) - curve1.GetEndPoint(0);
Autodesk.Revit.DB.XYZ vector2 = curve2.GetEndPoint(1) - curve2.GetEndPoint(0);
bool flag = vector.Normalize().DotProduct(vector2.Normalize()).Equals(0);
if (flag) throw new Exception("The two curves are not perpendicular");
// review main pipe branch
XYZ firstPoint = curve1.GetEndPoint(0);
XYZ secondPoint = curve2.GetEndPoint(0);
Autodesk.DesignScript.Geometry.Line? protoType = curve2.ToProtoType(false) as Autodesk.DesignScript.Geometry.Line;
Autodesk.DesignScript.Geometry.Point pointProjected = Point.ProjectOnToLine(firstPoint.ToPoint(false),protoType
);
Revit.Elements.Element? mainMEPCurve = null;
Revit.Elements.Element? branchMEPCurve = null;
bool isOnLine = Point.IsOnLine(pointProjected,protoType);
if (isOnLine)
{
mainMEPCurve = MepCurve2;
branchMEPCurve = MepCurve1;
}
else
{
mainMEPCurve = MepCurve1;
branchMEPCurve = MepCurve2;
protoType = curve1.ToProtoType(false) as Autodesk.DesignScript.Geometry.Line;
pointProjected = Point.ProjectOnToLine(secondPoint.ToPoint(false),protoType);
isOnLine = Point.IsOnLine(pointProjected,protoType);
if(!isOnLine) throw new Exception("The two curves are can't create a tee fitting");
}
// create tee
TransactionManager.Instance.ForceCloseTransaction();
Autodesk.Revit.DB.Document doc = DocumentManager.Instance.CurrentDBDocument;
TransactionManager.Instance.EnsureInTransaction(doc);
protoType = mainMEPCurve.GetLocation() as Autodesk.DesignScript.Geometry.Line;
Autodesk.DesignScript.Geometry.Line? line = branchMEPCurve.GetLocation() as Autodesk.DesignScript.Geometry.Line;
pointProjected = Point.ProjectOnToLine(line.StartPoint,protoType);
Revit.Elements.Element? newMepCurve = MEPCurve.BreakCurve(mainMEPCurve,pointProjected);
TransactionManager.Instance.TransactionTaskDone();
Connector? c1 = ConnectorManager.Connector.GetConnectorClosest(newMepCurve,mainMEPCurve);
Connector? c2 = ConnectorManager.Connector.GetConnectorClosest(mainMEPCurve,branchMEPCurve);
List<Connector?> connectors = ConnectorManager.Connector.GetConnectors(branchMEPCurve);
Connector? c3 = ConnectorManager.Connector.GetConnectorClosest(c1.Origin.ToPoint(), connectors);
Revit.Elements.Element? teeFitting = Fitting.NewTeeFitting(c1, c2, c3);
return teeFitting;
}

/// <summary>
/// Add a new family instance of an transition fitting into the Autodesk Revit document,
/// using two connectors.
Expand Down
1 change: 0 additions & 1 deletion OpenMEP/Helpers/Convert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,6 @@ internal static Autodesk.DesignScript.Geometry.Vector ToDynamoVector(this XYZ it
return item.ToProtoType();
;
}

/// <summary>
/// Convert Dynamo Curve to Revit Line
/// </summary>
Expand Down
5 changes: 2 additions & 3 deletions OpenMEPSandbox/Geometry/Point.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public static Autodesk.DesignScript.Geometry.Point ProjectOntoPlane(
/// <example>
/// ![](../OpenMEPPage/geometry/dyn/pic/Point.ProjectOnToLine.gif)
/// </example>
public static Autodesk.DesignScript.Geometry.Point ProjectOnToLine(Autodesk.DesignScript.Geometry.Point point,
Autodesk.DesignScript.Geometry.Line line)
public static Autodesk.DesignScript.Geometry.Point ProjectOnToLine(Autodesk.DesignScript.Geometry.Point? point,
Autodesk.DesignScript.Geometry.Line? line)
{
Autodesk.DesignScript.Geometry.Vector lineDirection = line.Direction.Normalized();
Autodesk.DesignScript.Geometry.Point start = line.StartPoint;
Expand All @@ -52,7 +52,6 @@ public static Autodesk.DesignScript.Geometry.Point ProjectOnToLine(Autodesk.Desi
return ProjectedPoint;
}


/// <summary>
/// Get the centroid of a list of points
/// </summary>
Expand Down
202 changes: 202 additions & 0 deletions docs/OpenMEPPage/element/dyn/MEPCurve.NewTeeFitting.dyn
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
{
"Uuid": "68c7fafb-c9ef-4d5d-b8ad-ed2ed0a644c8",
"IsCustomNode": false,
"Description": "",
"Name": "MEPCurve.NewTeeFitting",
"ElementResolver": {
"ResolutionMap": {}
},
"Inputs": [],
"Outputs": [],
"Nodes": [
{
"ConcreteType": "Dynamo.Graph.Nodes.ZeroTouch.DSFunction, DynamoCore",
"NodeType": "FunctionNode",
"FunctionSignature": "[email protected],Revit.Elements.Element",
"Id": "77b701e5fa494a4cbe7ebf79d2f13b35",
"Inputs": [
{
"Id": "f421f00e6b204e4d9d215f112957d730",
"Name": "MepCurve1",
"Description": "the first element mep curve\n\nElement",
"UsingDefaultValue": false,
"Level": 2,
"UseLevels": false,
"KeepListStructure": false
},
{
"Id": "18d295ead9684ad7bc376a2ef0e490ee",
"Name": "MepCurve2",
"Description": "the second element mep curve\n\nElement",
"UsingDefaultValue": false,
"Level": 2,
"UseLevels": false,
"KeepListStructure": false
}
],
"Outputs": [
{
"Id": "e70f0192d8264bdcaf9db1dd91969210",
"Name": "familyinstance",
"Description": "the element family instance",
"UsingDefaultValue": false,
"Level": 2,
"UseLevels": false,
"KeepListStructure": false
}
],
"Replication": "Auto",
"Description": "Create a new tee fitting 90 degrees by two mep curve\n\nMEPCurve.NewTeeFitting (MepCurve1: Element, MepCurve2: Element): Element"
},
{
"ConcreteType": "Dynamo.Nodes.DSModelElementSelection, DSRevitNodesUI",
"NodeType": "ExtensionNode",
"InstanceId": [
"ae2bc04f-25d9-41dd-99b5-0c4788ce76a2-000d9ecc"
],
"Id": "67ec0c060b5d4d87895c6cd457942c9a",
"Inputs": [],
"Outputs": [
{
"Id": "ccfe90dc6d7c4c018fcf3bff4b7f7f8f",
"Name": "Element",
"Description": "The selected elements.",
"UsingDefaultValue": false,
"Level": 2,
"UseLevels": false,
"KeepListStructure": false
}
],
"Replication": "Disabled"
},
{
"ConcreteType": "Dynamo.Nodes.DSModelElementSelection, DSRevitNodesUI",
"NodeType": "ExtensionNode",
"InstanceId": [
"ae2bc04f-25d9-41dd-99b5-0c4788ce76a2-000d9edd"
],
"Id": "6daa057f19ce4cc9ae27847a12243fe2",
"Inputs": [],
"Outputs": [
{
"Id": "a2f7a6341e7041edbd2dd6899ce5e0aa",
"Name": "Element",
"Description": "The selected elements.",
"UsingDefaultValue": false,
"Level": 2,
"UseLevels": false,
"KeepListStructure": false
}
],
"Replication": "Disabled"
}
],
"Connectors": [
{
"Start": "ccfe90dc6d7c4c018fcf3bff4b7f7f8f",
"End": "18d295ead9684ad7bc376a2ef0e490ee",
"Id": "0c7f93e67dcc4081919e6f600bb4395a",
"IsHidden": "False"
},
{
"Start": "a2f7a6341e7041edbd2dd6899ce5e0aa",
"End": "f421f00e6b204e4d9d215f112957d730",
"Id": "6f0dba91c6064ac8a520718291d73ef7",
"IsHidden": "False"
}
],
"Dependencies": [],
"NodeLibraryDependencies": [
{
"Name": "OpenMEP",
"Version": "1.0.0",
"ReferenceType": "Package",
"Nodes": [
"77b701e5fa494a4cbe7ebf79d2f13b35"
]
}
],
"Thumbnail": "",
"GraphDocumentationURL": null,
"ExtensionWorkspaceData": [
{
"ExtensionGuid": "28992e1d-abb9-417f-8b1b-05e053bee670",
"Name": "Properties",
"Version": "2.16",
"Data": {}
},
{
"ExtensionGuid": "DFBD9CC0-DB40-457A-939E-8C8555555A9D",
"Name": "Generative Design",
"Version": "3.0",
"Data": {}
}
],
"Author": "",
"Linting": {
"activeLinter": "None",
"activeLinterId": "7b75fb44-43fd-4631-a878-29f4d5d8399a",
"warningCount": 0,
"errorCount": 0
},
"Bindings": [],
"View": {
"Dynamo": {
"ScaleFactor": 1.0,
"HasRunWithoutCrash": true,
"IsVisibleInDynamoLibrary": true,
"Version": "2.16.1.2727",
"RunType": "Manual",
"RunPeriod": "1000"
},
"Camera": {
"Name": "Background Preview",
"EyeX": -17.0,
"EyeY": 24.0,
"EyeZ": 50.0,
"LookX": 12.0,
"LookY": -13.0,
"LookZ": -58.0,
"UpX": 0.0,
"UpY": 1.0,
"UpZ": 0.0
},
"ConnectorPins": [],
"NodeViews": [
{
"Name": "MEPCurve.NewTeeFitting",
"ShowGeometry": true,
"Id": "77b701e5fa494a4cbe7ebf79d2f13b35",
"IsSetAsInput": false,
"IsSetAsOutput": false,
"Excluded": false,
"X": 525.3542627499728,
"Y": 276.979867546608
},
{
"Name": "Select Model Element",
"ShowGeometry": true,
"Id": "67ec0c060b5d4d87895c6cd457942c9a",
"IsSetAsInput": false,
"IsSetAsOutput": false,
"Excluded": false,
"X": 207.15956789979305,
"Y": 210.65682751455071
},
{
"Name": "Select Model Element",
"ShowGeometry": true,
"Id": "6daa057f19ce4cc9ae27847a12243fe2",
"IsSetAsInput": false,
"IsSetAsOutput": false,
"Excluded": false,
"X": 206.56176389544032,
"Y": 383.4221847724985
}
],
"Annotations": [],
"X": -132.12192800565981,
"Y": -72.06579096584079,
"Zoom": 1.13758205229474
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 743a050

Please sign in to comment.