Setting Project Units - From Millimetres to Metres Automatically

Hey All,

I’m in the process of creating a portal frame ‘generator’ for a trial generative design through Robot - One slight issue I’m having is that my company Revit template is set in mm. For easiness within Dynamo, I’ve done this in metres, so I get the nice little grid! I don’t really want to have to keep changing Project Units each time. So I’m wondering whether this is possible through a python coding?

I’ve tried all node based parameter’s however I can’t seem to get Project Units. I’ve created the python coding from the topic below, but this only calls up the current project unit setting. Could anyone give me a hand with a code which automatically changes the project units to metres!?

[Project unit settings](https://forum.dynamobimDetect Units.dyn (1.3 KB)
.com/t/project-unit-settings/2560)

Thanks!

1 Like

Hi Daniel!

You can do something like this:

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_METERS)
	unit.SetFormatOptions(UnitType.UT_Length,format)
	doc.SetUnits(unit)
	TransactionManager.Instance.TransactionTaskDone()
	OUT = "length unit changed to meter"
else:
	OUT = "Set IN[0] to true!"

unitToMeter.dyn (1.9 KB)

16 Likes

Thanks @Einar_Raknes!

Hi Guys,

I’m a total noobie to dynamo and know very little about python.

Was just wondering if it is possible to modify this script to leave at mm but set the decimal places of the length and angle to 3 decimal places?

I’d appreciate any help

Thanks

Hello @hargreaves102

Could you try to replace this line:
format = FormatOptions(DisplayUnitType.DUT_METERS)
with
format = FormatOptions(DisplayUnitType.DUT_METERS,0.001)
and let us know if it works for you?

4 Likes

This worked great for the Length thank you very much Einar.

Is there a similar fix for changing the angle to 3 decimal places?

Take a look at the different unit types here: http://www.revitapidocs.com/2018/4155880c-f243-3456-fbb8-542c8f8ad692.htm

And the Display Unit Types here: http://www.revitapidocs.com/2018/7d3d3306-a4c2-c577-0aeb-cca42d6cfd2f.htm

I guess a combination of DisplayUnitType.DUT_DECIMAL_DEGREES and UnitType.UT_Angle would work. Give it a shot an let us know how it goes.

2 Likes

Again, your a lifesaver. This has worked perfectly.

Thanks for taking the time to help out, its appreciated!

How would I add other options to this? Options like UnitSymbolType and Suppress Trailing 0’s?

Did you end up figuring this part out?

@The_Minty For UnitSymbolType and in the case of millimeters, I added
UnitSymbolType.UST_MM. So, Line 16 of the above code from Einar_Raknes now looks like this:

format = FormatOptions(DisplayUnitType.DUT_MILLIMETERS,UnitSymbolType.UST_MM)

I also referenced this page for UnitSymbolType enumeration:
http://www.revitapidocs.com/2018/1a6d5d01-d835-c419-c14a-4cd25f563ea0.htm

2 Likes

How to add to the script the modification of usedigitgrouping and digitgroupingsymbol?

2 posts were split to a new topic: Setting Project Units - set Accuracy

Hello, does anyone know how to add a precision of 0.001 on top of the changes you talk about?
I am trying:

format = FormatOptions(DisplayUnitType.DUT_METERS,0.001, UnitSymbolType.UST_M)

Notice this 0.001 in the middel but doesnt seem to work, I also need to add this precision change and I dont know where to put it or how to get it in the logic