I need to do this ask… Just a little help on how to do it in dynamo? or code block?
With the API and Python.
Don’t know if anyone has made a node for these.
I saw this one… I just need to figure out how to read it…
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
if IN[0]:
TransactionManager.Instance.EnsureInTransaction(doc)
unit = doc.GetUnits()
format = FormatOptions(DisplayUnitType.DUT_MILLIMETERS, 0.01)
unit.SetFormatOptions(UnitType.UT_Length,format)
doc.SetUnits(unit)
TransactionManager.Instance.TransactionTaskDone()
OUT = "length unit changed to millimeter"
else:
OUT = "Set IN[0] to true!"
For future reference, please post code inside preformatted text (</>
) so that it gets formatted properly.
1 unit = doc.GetUnits()
2 format = FormatOptions(DisplayUnitType.DUT_MILLIMETERS, 0.01)
3 unit.SetFormatOptions(UnitType.UT_Length,format)
4 doc.SetUnits(unit)
- Get the project units.
- Get the type of units and rounding.
- Format the unit type and rounding for the specified unit.
- Apply the unit formatting back to the project units.
Thanks for the explanation… but is there no 5? Set the “unit symbol” to none…
I was just explaining those lines of the code you posted. In order to change the symbol display you would also have to use the FormatOptions for UnitSymbolType.
https://www.revitapidocs.com/2020/1058a15c-711c-db20-3f11-c9c6a71f113c.htm
Awesome, exactly what i need… thank you
so why is it that it worls in R20 but not in R22 ? change in API?
Exactly.
Units were transitioned to ForgeTypeIds. This is the new method:
https://www.revitapidocs.com/2021.1/64822a98-a253-3300-cdbb-17973687878f.htm
Just to complete this thread… The similar solution was found here.