How to extract length of a curve using python code

i would like to extract length of a pipe using python code. I don’t know how to use properties of a class. I wrote as shown below.

import clr
clr.AddReference(‘ProtoGeometry’)
from Autodesk.DesignScript.Geometry import *
clr.AddReference(‘RevitApi’)
from Autodesk.Revit.DB import *
#from Autodesk.Revit.DB.HostedSweep import *
clr.AddReference(“RevitNodes”)
import Revit
clr.AddReference(“RevitServices”)
import RevitServices
from RevitServices.Persistence import *
from RevitServices.Transactions import *
clr.ImportExtensions(Revit.GeometryConversion)
doc = DocumentManager.Instance.CurrentDBDocument
uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

sel = uidoc.Selection.GetElementIds()

stlist=
endlist=
length =
for i in sel:
item = (doc.GetElement(i))
loc = item.Location
len = item.Length
start = item.Location.Curve.GetEndPoint(0)
end = item.Location.Curve.GetEndPoint(1)
stlist.append(start)
endlist.append(end)
length.append(len)
OUT =stlist,endlist,length

image

Use LookupParameter to get the parameter by name.
http://www.revitapidocs.com/2018.1/4400b9f8-3787-0947-5113-2522ff5e5de2.htm

2 Likes

Can you show what error you are getting? Just off the script you’ve shown, shouldn’t the import for clr.AddReference(“RevitApi”) be “RevitAPI”, because it should be case sensitive.

I corrected as below. now its working.

image

1 Like