Dynamo Python Primer
  • Take Dynamo Further 🚀
  • 1 Hello Python 🐍
    • 1.1 Why Should I Learn to Code?
    • 1.2 Python Introduction
    • 1.3 What is IronPython?
  • 2 Seeing The Bigger Picture 🔭
    • 2.1 Context Matters
    • 2.2 What is an API?
    • 2.3 The .NET Framework
    • 2.4 Object-Oriented Programming
  • 3 Getting Started 🛴
    • 3.1 Dynamo's Python Node
    • 3.2 Boilerplate Setup Code
    • 3.3 Basics: Input and Output
    • 3.4 Common Errors
  • 4 Revit-Specific Topics 🏡
    • 4.1 Introduction to Revit's API
    • 4.2 How to Read Revit's API Documentation
    • 4.3 Doc, UIDoc, App, UIApp
    • 4.4 Unwrapping Revit Elements
    • 4.5 The FilteredElementCollector
    • 4.6 Geometry Conversion Methods
    • 4.7 Working With Parameters
      • Family Parameters
      • Global Parameters
      • Project Information Parameters
      • Group Parameters
      • Built-In Parameters
    • 4.8 Working With Transactions
    • 4.9 Opening & Closing External Files
    • 4.10 Prompting UI Selection
    • 4.11 Working With Units
    • 4.12 Built-In Categories
    • 4.13 Family Acrobatics
    • 4.14 Feedback: TaskDialogs
  • 5 Glossary 📚
  • About This Primer 👋
Powered by GitBook
On this page

Was this helpful?

  1. 4 Revit-Specific Topics 🏡

4.11 Working With Units

Feet, Inches, Meters and Millimetres

Previous4.10 Prompting UI SelectionNext4.12 Built-In Categories

Last updated 2 years ago

Was this helpful?

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 class. Furthermore, we'll be restricted to choosing value types from Revit's 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
UnitUtils
DisplayUnitType