Deactivate default unit project settings
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi everyone!
I am working on a code to remove unit symbols on all the selected schedule fields, by now my code is working well over the fields which are not configured to use default project settings, but for those ones using default project settings I am receiving this error:
" Exception : Autodesk.Revit.Exceptions.InvalidOperationException: UseDefault is true in this FormatOptions.
at Autodesk.Revit.DB.FormatOptions.GetUnitTypeId()
at Microsoft.Scripting.Interpreter.FuncCallInstruction`2.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.LightLambda.Run3[T0,T1,T2,TRet](T0 arg0, T1 arg1, T2 arg2)
at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
at Microsoft.Scripting.Interpreter.DynamicInstruction`3.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)"
If I manually deactivates the use project settings from the Revit UI the code works well, I would like to know if is possible to deactivate that option from the code, I thought the UseDefault property set to None would do this, but in this specific case it is not doing it, this is the code I am using:
ids = uidoc.Selection.GetElementIds()
for id in ids:
sched = doc.GetElement(id)
t = Transaction(doc, "Remove Unit Symbol")
t.Start()
#Get Schedule Definition
sched_def = sched.Definition
field_count = sched_def.GetFieldCount()
f_index = range(field_count)
#Itering over the schedule fields
for i in f_index:
field = sched_def.GetField(i)
field_name = field.GetName()
print (field_name)
#try:
# Get current FormatOptions from the field
format_options = field.GetFormatOptions()
unit_type_id = format_options.GetUnitTypeId()
accuracy = format_options.Accuracy
formatOpts = FormatOptions(unit_type_id)
formatOpts.UseDefault = False
formatOpts.Accuracy = accuracy
formatOpts.RoundingMethod.Nearest
field.SetFormatOptions(formatOpts)
print("Succesfully unit symbol removed")
#except:
#pass
#print("Error on unit setting")
t.Commit()
What I am doing wrong in my code?, I have attached an image for reference.
Thanks in advance!, greetings from Mexico city.
Developer Advocacy and Support + 