Expected Level, got Level

Hi
I use Revit Node library to create new Elements.
I push: Line, Level and FamilyType but Dynamo Python show Error

But the same arguments and create by Dynamo Node work fine.

import clr

clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Structure import *

clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

p1 = XYZ()
p2 = XYZ(2,0,0)
line = Line.CreateBound(p1,p2).ToProtoType()

#get familytype
ftype = Revit.Elements.FamilyType.ByFamilyNameAndTypeName("UB-Universal Beams","UB305x165x40")

#get level
Alllevel = FilteredElementCollector(doc).OfClass(Level).WhereElementIsNotElementType().ToElements()
level = Alllevel[1]

#OUT = line,level,ftype

#Create beam
beam = Revit.Elements.StructuralFraming.BeamByCurve(line,level,ftype)

OUT = beam

ExpectedLevel.dyn (16.0 KB)

I tried change level to IN[0] and it worked, :rofl:


ExpectedLevel.dyn (17.1 KB)

This is a call to the Dynamo node for creating a beam, so all of the inputs need to be Dynamo wrapped elements of their Revit equivalent. Instead of wrapping it is likely easier to use the Revit API call directly, as both your level and curve are already Revit native data types.

I believe that this is the API call to create a beam: NewFamilyInstance Method (Curve, FamilySymbol, Level, StructuralType)

You will also need to change your method for collecting the family type, utilizing a filtered element collector as you did in the levels instead of the by family name and type call to the Dynamo node.

You will also need to provide the structural type, the method of which is here: StructuralType Enumeration

2 Likes

Hi,

Try to wrapp the level into DynamoObject ( necessary to import extension)

level = Alllevel[0].ToDSType(True)

2 Likes

Thank you so much!

1 Like