22 Mar 2024
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.
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
/AK at 14:41 UTC