How to Get Unit Symbol of a Unit Type

python
dynamo
units

#1

I’m trying to get the Unit symbol for a unit type of a parameter. I wrote the following script:

import clr
# Import DocumentManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager

# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import LabelUtils


doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application

Unittypes = IN[0]
UnitNames = []

for i in range(len(Unittypes)):
	formatoptions = doc.GetUnits().GetFormatOptions(Unittypes[i])
	dispunits = formatoptions.DisplayUnits
	symtype = formatoptions.UnitSymbol
	UnitNames.append(LabelUtils.GetLabelFor(symtype))
		
OUT = UnitNames

But when I run the script I receive the following error:

Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed. 
Traceback (most recent call last):
  File "<string>", line 21, in <module>
TypeError: expected UnitType, got str

Can anybody help, explaining the way for getting the Unit symbol for a unit type


#2

Show complete graph with all the previews.


#3

sure, @Kulkul. Please see the below graph. Hope this will be helpful.


#4

the problem is as the error states - the unitType node returns a list of strings, the function you’re calling accepts parameters of type UnitType - which I think are an enum - someone more familiar with ironPython might know how to parse the string to a python object which represents the .net enum…