DisplayUnitType not defined error

Hi! I am trying to create levels depending on the elevations from a model, but I am getting an error that says DisplayUnitType not defined. The script worked correctly on Revit 2021, but it does not in Revit 2022.

# Load the Python Standard and DesignScript Libraries
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference ('RevitNodes')
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)

doc = DocumentManager.Instance.CurrentDBDocument


#Insert elevations from the model
elevations = IN[0]
elevations.sort()

#Get the levels from the model and convert them to Dynamo elements
collector = FilteredElementCollector(doc)
levels = collector.OfCategory(BuiltInCategory.OST_Levels).ToElements()
levels = levels[1:]

#levels = UnwrapElement(levels)[1:]

#levels2= []
TransactionManager.Instance.EnsureInTransaction(doc)
output = []

for l in range(len(levels)):
        e = elevations[l]
        e_name = str(round(e,3))
        e = UnitUtils.ConvertToInternalUnits(e,DisplayUnitType.DUT_METERS)
        l = levels[l]
        elevation = l.get_Parameter(BuiltInParameter.LEVEL_ELEV)
        name = l.get_Parameter(BuiltInParameter.DATUM_TEXT)
        elevation.Set(e)
        name.Set('Level '+str(e_name))


for e in elevations[len(levels):]:
        e_name = str(round(e,3))
        e = UnitUtils.ConvertToInternalUnits(e,DisplayUnitType.DUT_METERS)
        output.append(e_name)
        level = Level.Create(doc,e).ToDSType(False)

TransactionManager.Instance.TransactionTaskDone()

levels = collector.OfCategory(BuiltInCategory.OST_Levels).ToElements()
levels = levels[1:]





OUT = levels

They changed the API which would have an affect on this in 2022.

2 Likes