architecture-building-systems / revitpythonshell

An IronPython scripting environment for Autodesk Revit and Vasari
MIT License
490 stars 112 forks source link

DB.Units.SetFormatOptions() does not accept expect ForgeTypeId #134

Open onomou opened 1 year ago

onomou commented 1 year ago

Describe the bug DB.Units.SetFormatOptions() expects UnitType, but should also expect ForgeTypeId

To Reproduce

units = doc.GetUnits()
specs = units.GetModifiableSpecs()
target_spec = next(iter(x for x in specs if LabelUtils.GetLabelForSpec(x) == 'Length'))
target_options = units.GetFormatOptions(target_spec)
target_units = UnitUtils.GetValidUnits(target_spec)
target_unit = next(iter(x for x in target_units if LabelUtils.GetLabelForUnit(x) == 'Fractional inches'))
units.SetFormatOptions(target_spec, target_unit)

Output:

Exception : Microsoft.Scripting.ArgumentTypeException: expected UnitType, got ForgeTypeId
   at Microsoft.Scripting.Interpreter.ThrowInstruction.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.LightLambda.Run5[T0,T1,T2,T3,T4,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4)
   at System.Dynamic.UpdateDelegates.UpdateAndExecute4[T0,T1,T2,T3,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3)
   at Microsoft.Scripting.Interpreter.DynamicInstruction`5.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1)
   at IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx)
   at Microsoft.Scripting.Hosting.ScriptSource.Execute(ScriptScope scope)
   at Microsoft.Scripting.Hosting.ScriptSource.ExecuteAndWrap(ScriptScope scope, ObjectHandle& exception)

Expected behavior RevitPythonShell should execute SetFormatOptions(ForgeTypeId, FormatOptions) and set the specified unit.

Screenshots image

Desktop (please complete the following information):

Additional context The tooltip indicates that both SetFormatOptions(UnitType, FormatOptions) and SetFormatOptions(ForgeTypeId, FormatOptions) are available.

SetFormatOptions API documentation