StructuralFraming.BeamByCurve in python

Hi,I want to use “StructuralFraming.BeamByCurve” in python. Now I can use curve and FamilyType in python,but meet a mistake when using Level

import clr
clr.AddReference("RevitAPI")
clr.AddReference("RevitAPIUI")
import Autodesk
from Autodesk.Revit.DB import *
from Autodesk.Revit.UI import *
clr.AddReference("ProtoGeometry")
from Autodesk.DesignScript.Geometry import *
clr.AddReference("RevitNodes")
from Revit.Elements import *
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument
lv=IN[0]
a=Point.ByCoordinates(5,5,0)
b=Point.ByCoordinates(25,0,0)
line=Line.ByStartPointEndPoint(a,b)
Family=FamilyType.ByName("25mT梁")
level=FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Levels).WhereElementIsNotElementType().ToElements()[0]
beam=StructuralFraming.BeamByCurve(line,level,Family)
OUT=beam

Line 41 means “beam=StructuralFraming.BeamByCurve(line,level,Family)”
Any Idea why?

1 Like

I would be very careful about using known commands as variable names, things like Family = and level = as it can conflict with the commands using the same name. Start by changing the variable names into something more unique.

Another problem seems to be conflicting types between the Revit element Level and the Dynamo element Level. You are collecting the Revit element Level through the doc but the Dynamo command
StructuralFraming.BeamByCurve() wants the Dynamo version. I think the command for that is .ToDSType()

2 Likes

Thx,bro! I change the variable name,and use .ToDSType() ,I can bulid the beam.

Thx,bro! I change the variable names and use the .ToDSType(),the question is solved!

1 Like

No problem! Don’t forget to mark the post solved by clicking the Solution button on the post that helped.

1 Like

Hi, mate. Your work looks very impressive. May I ask do you know how to use StructuralFraming.ColumnByCurve in Python? Should I make some change on the “level”?

Oops, I’ve found the reason why my column doesn’t work. I used the same name for the family type of column and beam. :joy: :joy: Sorry for the bothering.