Hi All. I know there is a similar topic to this one. Question is, what code do I replace DisplayUnitType with? I know it changed in the api but cant find the correct syntax. So with the below, what do I simply need to change it to the correct syntax?
def locToCutCrv(wall, wallNormal, lineEndExtend, locPos):
wallLn = wall.Location.Curve
#we’re using Design Script for the geometry move, so Metric units
wallCrv = wallLn.ToProtoType()
locPositionMM = UnitUtils.ConvertFromInternalUnits(locPos, DisplayUnitType.DUT_MILLIMETERS)
Hi @technitutors ,
Maybe this will help?
import Autodesk.Revit.DB as RDB
revit_version = int(doc.Application.VersionNumber)
# code omrekenen revit feet naar huidig ingestele document units
if revit_version >= 2022:
ForgeLength = "autodesk.spec.aec:length-1.0.0" # zie voor lijst ForgeTypeIds.xlsx in de map handleidingen
ForgeTypeLength = RDB.ForgeTypeId(ForgeLength)
getDocUnits = doc.GetUnits()
getDisplayUnitsLength = getDocUnits.GetFormatOptions(ForgeTypeLength).GetUnitTypeId()
else:
getDocUnits = doc.GetUnits()
getDisplayUnits = getDocUnits.GetFormatOptions(RDB.UnitType.UT_Length).DisplayUnits
# Hieronder kun je de definitions gaan opzetten
#dynamo waarde omzetten naar revit units length
def ToRevitUnitsLength(InVal):
if revit_version >= 2022:
return RDB.UnitUtils.ConvertToInternalUnits(InVal, getDisplayUnitsLength)
else:
return RDB.UnitUtils.ConvertToInternalUnits(InVal, getDisplayUnits)
#revit waarde omzetten naar dynamo units length
def ToDynamoUnitsLength(InVal):
if revit_version >= 2022:
return RDB.UnitUtils.ConvertFromInternalUnits(InVal, getDisplayUnitsLength)
else:
return RDB.UnitUtils.ConvertFromInternalUnits(InVal, getDisplayUnits)
#dynamo waarde omzetten naar revit units length van mm
def ToRevitUnitsLengthFromMM(InVal):
if revit_version >= 2022:
return RDB.UnitUtils.Convert(InVal, RDB.UnitTypeId.Millimeters, RDB.UnitTypeId.Feet)
else:
return RDB.UnitUtils.Convert(InVal, RDB.DisplayUnitType.DUT_MILLIMETERS, RDB.DisplayUnitType.DUT_DECIMAL_FEET)
1 Like
so this goes before the script I wrote?
What revit version you are using ?
In Revit 2023, you should update API
Older Revit 2023 :
locPositionMM = UnitUtils.ConvertFromInternalUnits(locPos, DisplayUnitType.DUT_MILLIMETERS)
Revit 2023 or higher :
locPositionMM = UnitUtils.ConvertFromInternalUnits(locPos, UnitTypeId.Millimeters)
3 Likes
@technitutors
You can use this def.
It is the same what @chuongmep suggest, this definition can be used in every revit version.
1 Like