I am new to Dynamo and have been assigned a task to design a script to calculate length of a conduit fitting. I have an idea how it can be calculated on paper, however, no idea how todo it in Dynamo.
In picture above we have: L - length we want to find; a - angle of conduit fitting; y - which is predefined value of 10mm; x - radius, if conduit has a nominal radius of 10mm then x = 13.8mm, however, it would be good to implement formula to calculate x depending on nominal radius of conduit;
Total length of conduit fitting would consist of 2y+L.
Please, share your ideas, tips on how to solve this.
import clr
import sys
import System
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
import Autodesk.DesignScript.Geometry as DS
#import Revit API
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
import Autodesk.Revit.DB as DB
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument
def get_length_fitting(elem):
"""
return the arc geometry an the length
"""
if hasattr(elem, "MEPModel"):
conSet = elem.MEPModel.ConnectorManager.Connectors
if conSet.Size == 2:
pair_sys_origin = [[con.CoordinateSystem, con.Origin] for con in conSet]
pta = pair_sys_origin[0][1].ToPoint()
ptb = pair_sys_origin[1][1].ToPoint()
vector = pair_sys_origin[0][0].BasisZ.Negate().ToVector()
arc = DS.Arc.ByStartPointEndPointStartTangent(pta, ptb, vector)
return arc.Length
else:
return None #The fitting have more than 2 connectors
return None #The Element is not a fitting
toList = lambda x : x if hasattr(x, '__iter__') else [x]
#Preparing input from dynamo to revit
lstfitting = toList(UnwrapElement(IN[0]))
OUT = [get_length_fitting(e) for e in lstfitting]