Python script in Dynamo Graphs not working properly in Revit 2022 (Project Units)

Hi,

I created a Dynamo graph that modify the project units (imperial or metric) and it doesn’t work anymore with Revit 2022. I saw that there was some modification to the API related to units in Revit 2022. I’m not programmer, I’m just someone that had interest in Dynamo so I don’t really know the terms in the industry. I know that DisplayUnitType was now replaced, but other than that, I don’t know how to make it work…

Here’s the part of the graph that now fail.

TransactionManager.Instance.EnsureInTransaction(doc)
unit = doc.GetUnits()
format = FormatOptions(DisplayUnitType.DUT_MILLIMETERS,1)
unit.SetFormatOptions(UnitType.UT_Length,format)
doc.SetUnits(unit)
TransactionManager.Instance.TransactionTaskDone()

Thank you!

Antony Roy

Hi @Antony.Roy,

Here is the updated script for Revit 2022 :

TransactionManager.Instance.EnsureInTransaction(doc)
unit = doc.GetUnits()
format = FormatOptions(UnitTypeId.Millimeters)
format.Accuracy = 1
unit.SetFormatOptions(SpecTypeId.Length,format)
doc.SetUnits(unit)
TransactionManager.Instance.TransactionTaskDone()
3 Likes

EXCELLENT!!! Thank you! It works now!

I still have issue to change the Unit symbol…

TransactionManager.Instance.EnsureInTransaction(doc)
unit = doc.GetUnits()
format = FormatOptions(UnitTypeId.Currency,UnitSymbolType.UST_DOLLAR)
format.Accuracy = 0.01
unit.SetFormatOptions(SpecTypeId.Currency,format)
doc.SetUnits(unit)
TransactionManager.Instance.TransactionTaskDone()

Do you have an idea on how to define them?

Thank you!

hello
try this

TransactionManager.Instance.EnsureInTransaction(doc)
unit = doc.GetUnits()
format = FormatOptions(UnitTypeId.Currency, SymbolTypeId.UsDollar )
format.Accuracy = 0.01
unit.SetFormatOptions(SpecTypeId.Currency, format)
doc.SetUnits(unit)
TransactionManager.Instance.TransactionTaskDone()
1 Like

Excellent.
It works…
Actually, I’ll have to manage many different unit symbols depending on the unit type…
Is there a list somewhere when I can find what are the new unit types?
Like… I’ll have to manage this one: UnitSymbolType.UST_KG_PER_CU_M

Thank you!

ok… found it…

https://www.revitapidocs.com/2021.1/81b89412-91e3-da6c-b103-0066a6c43fe4.htm

thanks for the help

1 Like

@Antony.Roy or @Alban_de_Chasteigner do you happen to know what the symboltypeid would be for using no symbol?

In Revit 2021 API it looked like this:
UnitSymbolType.UST_NONE

Try not to define them…

Instead of:

TransactionManager.Instance.EnsureInTransaction(doc)
unit = doc.GetUnits()
format = FormatOptions(UnitTypeId.Millimeters,SymbolTypeId.None)
format.Accuracy = 1
unit.SetFormatOptions(SpecTypeId.Length,format)
doc.SetUnits(unit)
TransactionManager.Instance.TransactionTaskDone()

Use:

TransactionManager.Instance.EnsureInTransaction(doc)
unit = doc.GetUnits()
format = FormatOptions(UnitTypeId.Millimeters)
format.Accuracy = 1
unit.SetFormatOptions(SpecTypeId.Length,format)
doc.SetUnits(unit)
TransactionManager.Instance.TransactionTaskDone()