Easy to do it manually, but can it be done proramatically?

I need to do this ask… Just a little help on how to do it in dynamo? or code block?
image

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)
  1. Get the project units.
  2. Get the type of units and rounding.
  3. Format the unit type and rounding for the specified unit.
  4. Apply the unit formatting back to the project units.
1 Like

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?image

Exactly.
image

Units were transitioned to ForgeTypeIds. This is the new method:
https://www.revitapidocs.com/2021.1/64822a98-a253-3300-cdbb-17973687878f.htm

3 Likes

Just to complete this thread… The similar solution was found here.