Convert this to Python3 please?

Hello,

this script does not seem to work anymore, in the new Dynamo 2.16.1 in Revit 2023.

How do I convert it to Pyhton 3?

thank you

import clr

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

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
from System.Collections.Generic import *

import System

doc = DocumentManager.Instance.CurrentDBDocument

result = Document.GetUnits(doc).GetFormatOptions(UnitType.UT_Length).DisplayUnits

#result = Document.DisplayUnitSystem.GetValue(doc)


OUT = result

Have you opened it in Revit 23?

What does the error say?

oops… sorry guys, I just could not run the custom node the code was in.

Will test more and see what error I get.

thanks

This is some update for Revit 2023, use SpecTypeId.Length

import clr

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

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
from System.Collections.Generic import *

import System

doc = DocumentManager.Instance.CurrentDBDocument

specTypeId = Document.GetUnits(doc).GetFormatOptions(SpecTypeId.Length).GetUnitTypeId()
label = Autodesk.Revit.DB.LabelUtils.GetLabelForUnit(specTypeId)

OUT = label
1 Like

In 2023 ForgeTypeId is now required:
This means that:
DisciplineTypeId replaces UnitGroup
SpecTypeId replaces ParameterType
GroupTypeId replaces BuiltInParameterGroup
ParameterTypeId replaces BuiltInParameter

You can always go long hand with just the direct ForgeTypeId for all of the above using the ForgeType string: ForgeTypeId(“autodesk.revit.parameter:viewDiscipline-1.0.0”)

Here’s the cheat sheet:
Revit Platform API Changes and Additions (typepad.com)