Units conversion Revit 2022

Hi,
I have a problem with the conversion of units in revit 2022. In revit 18.3 (i know its old - im new in dynamo :/ ) im using expression like this:
"

import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import DisplayUnitType, UnitUtils

# output unit
dut = DisplayUnitType.DUT_CENTIMETERS

OUT = UnitUtils.ConvertToInternalUnits(IN[0], dut)

";

but in revit 2022 there is some warnings:

“Ostrzeżenie:IronPythonEvaluator.EvaluateIronPythonScript operacja nie powiodła się.
Traceback (most recent call last):
File “”, line 4, in
ImportError: Cannot import name DisplayUnitType”

I have to convert units to centimeters to get surrounding elements for doors (like concrete beams), tolerance is 5 cm.

I know “DisplayUnitType Property Resource Not Available for the Active API Year” (2022), but maybe someone had the same problem and find solution.

Have a nice day!

See if this gets you headed in the right direction.

2 Likes

Thx SeanP, but its not working for me :confused:

I tried to rewrite the script but it still gets an error at the end.

Does anyone know conversion node which can work in this case

Try UnitTypeId.Milimeters in place of DusplayUnit.METRIC.

Nope :confused:

I tried too:

1 Like

Here is the API reference.

https://www.revitapidocs.com/2022/b5e8d065-d274-62f8-7b5d-89722f7c44f3.htm

It would help if I could spell.

Millimeters with 2 “LL”…

Or Meter or CM

Screenshot_20210907-044736

Try this.

"
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *

utid = UnitTypeId.MetersCentimeters

OUT = UnitUtils.ConvertToInternalUnits(IN[0],utid)
";

2 Likes

Haha, was just messing around with this, and the ForgeTypeId. Got way more complex then the actual answer :slight_smile:

That being said though, I think the OP needs the ConvertFrom :slight_smile:

import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import UnitUtils, UnitTypeId

wallType = UnwrapElement(IN[0])

widthInternal = wallType.Width

#output unit
uid = UnitTypeId.Millimeters

OUT = UnitUtils.ConvertFromInternalUnits(widthInternal, uid)

Image for context :slight_smile:

3 Likes

Hi, thank You for help!

Script works well with code like that:

I have to learn a lot :slight_smile: :slight_smile: :slight_smile:

2 Likes