4.11 Working With Units

Feet, Inches, Meters and Millimetres

How Revit Measures Lengths

When retrieving any length value using Revit's API, it will automatically be returned in decimal feet (for example, 6 inches = 0.5 Feet). Displaying lengths in any commonly-used format will require special conversion methods. In the example below, we feed a 5,000mm line into the Python Script node:

#Boilerplate Code

detail_line = UnwrapElement(IN[0])
decimal_feet_length = detail_line.GeometryCurve.Length
OUT = decimal_feet_length

The above code returns a value of 16.404, which is the same length but measured decimal feet.

Converting Between Units

Decimal feet isn't very useful to anyone so you'll want to convert to something more helpful. To make this conversion, we'll want to use Revit's UnitUtils class. Furthermore, we'll be restricted to choosing value types from Revit's DisplayUnitType enumeration. Let's see this in action:

For Revit version 2021 or lower

#Boilerplate Code

detail_line = UnwrapElement(IN[0])
decimal_feet_length = detail_line.GeometryCurve.Length
metric_length = UnitUtils.Convert(decimal_feet_length, DisplayUnitType.DUT_DECIMAL_FEET, DisplayUnitType.DUT_MILLIMETERS)
OUT = metric_length

For Revit version 2021 or higher


detail_line = UnwrapElement(IN[0])
decimal_feet_length = detail_line.GeometryCurve.Length
metric_length = Autodesk.Revit.DB.UnitUtils.Convert(decimal_feet_length, UnitTypeId.Feet, UnitTypeId.Millimeters)
OUT = metric_length

Bonus: Converting Rotations

Sometimes when passing an angle value in to the Revit API, it needs to be converted from degrees to radians first. This can also be done using UnitUtils.Convert(), like so:

For Revit version 2021 or lower

#Boilerplate Code

angle = 90.0
radians_equivalent = UnitUtils.Convert(angle, DisplayUnitType.DUT_DECIMAL_DEGREES, DisplayUnitType.DUT_RADIANS)
OUT = radians_equivalent

For Revit version 2021 or higher

#Boilerplate Code

angle = 90.0
radians_equivalent = UnitUtils.Convert(angle, UnitTypeId.Degrees, UnitTypeId.Radians)
OUT = radians_equivalent

Last updated