Converting units Syntexerror?

Hello,

I want to get my offsets in metric system f.e. mm

import System
import clr

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

clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *

clr.AddReference('System')
from System.Collections.Generic import List

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

wall = UnwrapElement(IN[0])

bottomext = UnitUtils.ConvertFromInternalUnits(wall.get_Parameter((BuiltInParameter.WALL_TOP_OFFSET).AsDouble(), DisplayUnitType.DUT_MILLIMETERS)
topext = UnitUtils.ConvertFromInternalUnits(wall.get_Parameter(BuiltInParameter.WALL_BASE_OFFSET).AsDouble(), DisplayUnitType.DUT_MILLIMETERS)

OUT = bottomext,topext

2022-05-20_08h42_15

so where is the issue

KR

Andreas


wall = UnwrapElement(IN[0])

bottomext = wall.get_Parameter(BuiltInParameter.WALL_BASE_OFFSET).AsDouble(),UnitTypeId.Feet,UnitTypeId.Millimeters

topext = wall.get_Parameter(BuiltInParameter.WALL_TOP_OFFSET).AsDouble(),UnitTypeId.Feet,UnitTypeId.Millimeters  


OUT = bottomext, topext

intresting result :wink:

@Draxl_Andreas the first code will work prior Revit 2022 due to API changes

so i have to be carefull @Elie.Trad just using API 2023

@Draxl_Andreas this is the new syntax for the conversion:

b = UnitUtils.Convert(wall.get_Parameter(BuiltInParameter.WALL_BASE_OFFSET).AsDouble(), UnitTypeId.Feet, UnitTypeId.Millimeters)

t = UnitUtils.Convert(wall.get_Parameter(BuiltInParameter.WALL_TOP_OFFSET).AsDouble(), UnitTypeId.Feet, UnitTypeId.Millimeters)

Edit: you can use the ConvertFromInternalUnits method as well:
b = UnitUtils.ConvertFromInternalUnits(wall.get_Parameter(BuiltInParameter.WALL_BASE_OFFSET).AsDouble(), UnitTypeId.Millimeters)

2 Likes

… the small things… so i have realy to snoop 2023 API , there are realy some diferences!

@Draxl_Andreas check the Revit API and the building coder for API changes between Revit versions:

1 Like