How to Get Unit type of a parameter and get it's unit symbol

Hi, I’m wondering if somehow I can get the unit symbol of any given element parameter. For example, if I have a list of mixed parameters. Some could be area, lengths, volumes… Is there any way for me to get a list of their Unit Symbols?

The method below didn’t work for me. Your help will be much appreciated.

I don’t believe Parameter and UnitType are the same. You would need to get the UnitType from the Parameter and then get the symbols.

Thank you for your answer. But still, can you tell me how i can do that? maybe there’s some specific node I’m not aware of. Sorry, I’m a bit new to dynamo.

@Nick_Boyts I tried to get the unit type from the parameter, but i need a node with unitType output maybe not a string. And even with this methode, i’m not sure if i can make it work. Thank you for your help.

You may have to use python.

@Nick_Boyts I can use python indeed, but the problem here, that i don’t understand why Parameter.UnitType give me this “Autodesk.Revit.DB.forgeTypeID” and don’t give me something like UT_Area or UT_Length?

Hard to say without any knowledge of your family or the parameter. Sounds like the parameter is coming from (or going through?) Forge if I had to guess. Try it with a builtin parameter first to make sure everything works the way you’d expect.

So I tried with a generic wall, chose the area as a parameter but still having this “ForgeTypeID”. The family I’m using are custom families that I made myself and the parameters I’m trying to get are all well configured if it’s an area or length or volume. What this Forge refers to?

Hey good sir !
Can you share your revit and dynamo versions ? because it works just fine for me !
Revit 2020.2
Dynamo 2.3


You should read this article : The Building Coder: PDF Export, ForgeTypeId and Multi-Target Add-In
The DisplayUnitType method is deprecated in Revit 2022.

1 Like

@Alban_de_Chasteigner beat me to it, but it looks like they changed units to Forge specs in 2021.

Here's a small summary.

Units API changes

Revit has converted to use an external reference to unit definitions defined in Forge schemas.

In the Autodesk.Revit.DB namespace, the enumerations DisplayUnitType, UnitSymbolType, and UnitType have been deprecated in favor of a potentially extensible set of units, symbols, and unit types. The new class:

  • Autodesk.Revit.DB.ForgeTypeId

represents an identifier for a unit, symbol, or other object, and is now used throughout the Revit API to identify units of measurement, symbols, and unit types. Unit types are now referred to as “specs” to avoid confusion with units themselves.

A ForgeTypeId instance holds a string, called a “typeid”, that uniquely identifies a Forge schema. A Forge schema is a JSON document describing a data structure, supporting data interchange between applications. A typeid string includes a namespace and version number and may look something like “autodesk.spec.aec:length-1.0.0” or “autodesk.unit.unit:meters-1.0.0”. By default, comparison of ForgeTypeId values in the Revit API ignores the version number.

The new classes:

  • Autodesk.Revit.DB.UnitTypeId
  • Autodesk.Revit.DB.SymbolTypeId
  • Autodesk.Revit.DB.SpecTypeId

contain a default set of named public constant properties of type ForgeTypeId. These values can be used in code replacing values of the deprecated DisplayUnitType, UnitSymbolType, and UnitType enumerations.

For example, where you previously used DisplayUnitType.DUT_WATTS_PER_SQUARE_METER_KELVIN, you would now use UnitTypeId.WattsPerSquareMeterKelvin. Where you previously used UnitType.UT_HVAC_Density, you would now use SpecTypeId.HvacDensity.

The UnitUtils class now offers a set of new methods for mapping between enumeration values and ForgeTypeId values to assist clients in migrating code to ForgeTypeId:

  • UnitUtils.IsSymbol()
  • UnitUtils.GetSpecTypeId()
  • UnitUtils.GetUnitType()
  • UnitUtils.GetUnitTypeId()
  • UnitUtils.GetDisplayUnitType()
  • UnitUtils.GetSymbolTypeId()
  • UnitUtils.GetUnitSymbolType()

Some of the preceding methods are new but are already deprecated. They have been added to the API only to assist clients in migrating code from the old enumerations to the ForgeTypeId class.

Hi @deejaypein, i’m using Revit 2021.3 and Dynamo 2.6.
@Alban_de_Chasteigner I was just reading this article and i’m so confused now on how i’m gonna change this Python code to work with the new APIs…

dispUnit = formatOption.DisplayUnits
replace by formatOption.GetUnitTypeId()

symType = formatOption.UnitSymbol
replace by formatOption.GetSymbolTypeId()

1 Like

I’m still able to use the same code in 2021.1 through python.

import clr
from Autodesk.Revit.DB import *
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
#The inputs to this node will be stored as a list in the IN variables.
dataEnteringNode = IN
e = UnwrapElement(IN[0])
param = IN[1]

p = e.LookupParameter(param)
v = p.AsValueString()
u = p.Definition.UnitType

#Assign your output to the OUT variable.
OUT = u
DisplayUnitType & UnitSymbol
import clr
from Autodesk.Revit.DB import *

import RevitServices
from RevitServices.Persistence import DocumentManager

dynunittype = IN[0]

unittype = dynunittype

doc = DocumentManager.Instance.CurrentDBDocument
formatoptions = doc.GetUnits().GetFormatOptions(unittype)
dispunits = formatoptions.DisplayUnits
symtype = formatoptions.UnitSymbol
if symtype == UnitSymbolType.UST_NONE:
	dispsym = None
	dispsym = LabelUtils.GetLabelFor(symtype)
OUT = (dispunits,dispsym)
1 Like

@Nick_Boyts Your UnitType Python Script worked fine for me on Revit 2021.3 but it works for only one input I guess. How I can get it to work for a list of elements Elements and Names as input?

@Alban_de_Chasteigner I just realized that my issue wasn’t in that script indeed but in the “Parameter.UnitType” node that I need to figure out how I can make it Show as result ‘UT_Area’ or ‘UT_Volume’ etc… Thank you guys for your valuable help!

Wrap it in a custom node or add looping to the code.

Thanks @Nick_Boyts i’ll try it and let you know about the outcome :slight_smile: .

Hello, @Nick_Boyts can you show how to wrap it in a custom node and how to add a looping in this script in order to make the script work for a list of elements rather than for one element?

Welcome to the forums, @Ninjo. I’d recommend working your way through the Dynamo Primer and searching through the forum posts for examples of both those questions. They’re fairly common and have already been answered many times before.