I’m trying to find a node/script that can change a documents unit type.
For example, changing the “distance” project units to imperial to metric:
I’ve tried tutorial on Youtube but they don’t work with the new api.
Thank you very much!
I’m trying to find a node/script that can change a documents unit type.
For example, changing the “distance” project units to imperial to metric:
I’ve tried tutorial on Youtube but they don’t work with the new api.
Thank you very much!
I don’t think there is a node that will update units
Here is some python code that can
import clr
clr.AddReference("RevitServices")
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import *
doc = DocumentManager.Instance.CurrentDBDocument
units = doc.GetUnits()
length = SpecTypeId.Length
feet_fi = UnitTypeId.FeetFractionalInches
current = units.GetFormatOptions(length).GetUnitTypeId()
if current != feet_fi:
units.SetFormatOptions(length, FormatOptions(feet_fi))
current = LabelUtils.GetLabelForUnit(current)
updated = LabelUtils.GetLabelForUnit(
units.GetFormatOptions(length).GetUnitTypeId()
)
TransactionManager.Instance.EnsureInTransaction(doc)
doc.SetUnits(units)
TransactionManager.Instance.TransactionTaskDone()
OUT = current, updated
Hi,
another example with Distance
and Length
unit
import clr
import sys
import System
#import Revit API
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
import Autodesk.Revit.DB as DB
#import transactionManager and DocumentManager (RevitServices is specific to Dynamo)
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
def set_millimeter_Unit():
TransactionManager.Instance.EnsureInTransaction(doc)
unit = doc.GetUnits()
format_opt = FormatOptions(Autodesk.Revit.DB.UnitTypeId.Millimeters)
format_opt.Accuracy = 1
unit.SetFormatOptions(SpecTypeId.Distance, format_opt )
unit.SetFormatOptions(SpecTypeId.Length, format_opt)
doc.SetUnits(unit)
TransactionManager.Instance.TransactionTaskDone()
set_millimeter_Unit()