Hello developers,
I am trying to create levels in Dynamo Python script using the function Level.ByLevelOffsetAndName(Level,Offset,Name)
But its throwing me a TypeError "Expected Level, got Level"
am not able to understand
Please Help Me…
Thank you
import clr
import sys
clr.AddReference('ProtoGeometry')
clr.AddReference("RevitNodes")
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.DesignScript.Geometry import *
# Import RevitNodes
import Revit
clr.AddReference('RevitServices')
clr.ImportExtensions(Revit.GeometryConversion)
from Revit import GeometryConversion
# Import Revit elements
from Revit.Elements import *
clr.ImportExtensions(Revit.Elements)
# Import DocumentManager
from Autodesk.Revit.DB import *
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
from Autodesk.DesignScript.Geometry import *
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
# The inputs to this node will be stored as a list in the IN variables.
levels = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Levels).WhereElementIsNotElementType().ToElements()
Revit.Elements.Level.ByLevelOffsetAndName(levels[7],12,"New Level")
TransactionManager.Instance.TransactionTaskDone()
# Assign your output to the OUT variable.
OUT = levels
Hi @rgoski329
You need to start a Transaction as well as ending it
1 Like
Hi @MartinSpence ,
Thank you for helping
I Did start the transaction after u said but still its showing the same error.
I see now that you are trying to call a node, and not an API call. I don’t know if you can access the nodes like that .
The API call to create a new level is this one: Link
1 Like
@rgoski329
if you want to use a DynamoRevit method, it’s necessary to wrapp your Revit API object
import clr
import sys
clr.AddReference('ProtoGeometry')
clr.AddReference("RevitNodes")
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.DesignScript.Geometry import *
# Import RevitNodes
import Revit
clr.AddReference('RevitServices')
clr.ImportExtensions(Revit.GeometryConversion)
from Revit import GeometryConversion
# Import Revit elements
from Revit.Elements import *
clr.ImportExtensions(Revit.Elements)
# Import DocumentManager
from Autodesk.Revit.DB import *
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
from Autodesk.DesignScript.Geometry import *
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
# The inputs to this node will be stored as a list in the IN variables.
levels = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Levels).WhereElementIsNotElementType().ToElements()
# wrapp the level
lvl = levels[7].ToDSType(True)
Revit.Elements.Level.ByLevelOffsetAndName(lvl,12,"New Level")
TransactionManager.Instance.TransactionTaskDone()
# Assign your output to the OUT variable.
OUT = levels
4 Likes
Hi @c.poupin ,
It Worked. Thank you so much.