Determine if Revit Display Units are Decimal or Fractional

22 Mar 2024

#visualprogramming #code #revit #dynamo #python

Python code that can be used in conjunction with Symbol.StringifyDecimal and Symbol.StringifyFraction to create Dynamo graphs that work with various unit display types in Revit.

Python Code

Note: This code is designed to work with Revit 2021 or later. It utilizes Forge schema API calls.

import clr

clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager

doc = DocumentManager.Instance.CurrentDBDocument
docUnitType = doc.GetUnits().GetFormatOptions(SpecTypeId.Length).GetUnitTypeId()

if docUnitType.TypeId == UnitTypeId.FeetFractionalInches.TypeId:
    result = "Fractional"
elif docUnitType.TypeId == UnitTypeId.FractionalInches.TypeId:
    result = "Fractional"
else:
    result = "Decimal"

OUT = result

Result

Determine-if-Revit-Display-Units-are-Decimal-or-Fractional-001.png

Determine-if-Revit-Display-Units-are-Decimal-or-Fractional-001.png

/AK at 14:41 UTC