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:
1
#Boilerplate Code
2
​
3
detail_line = UnwrapElement(IN[0])
4
decimal_feet_length = detail_line.GeometryCurve.Length
5
OUT = decimal_feet_length
Copied!
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:
1
#Boilerplate Code
2
​
3
detail_line = UnwrapElement(IN[0])
4
decimal_feet_length = detail_line.GeometryCurve.Length
5
metric_length = UnitUtils.Convert(decimal_feet_length, DisplayUnitType.DUT_DECIMAL_FEET, DisplayUnitType.DUT_MILLIMETERS)
6
OUT = metric_length
Copied!

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:
1
#Boilerplate Code
2
​
3
angle = 90.0
4
radians_equivalent = UnitUtils.Convert(angle, DisplayUnitType.DUT_DECIMAL_DEGREES, DisplayUnitType.DUT_RADIANS)
5
OUT = radians_equivalent
Copied!
Last modified 1yr ago
Copy link