Error: attribute 'CurrentUnitFromQuantityName' of 'namespace#' object is read-only

ANSYS version: 2021r2 & 2023r1 mechanical
I'm trying to build an ACT APP extension in mechanical, when I tried to run it below warning shows up.
attribute 'CurrentUnitFromQuantityName' of 'namespace#' object is read-only MissingMemberException at IronPython.Runtime.Binding.PythonGetMemberBinder.NamespaceTrackerDelegate.Target(CallSite site, Object self, CodeContext context) 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 Ansys.ACT.Core.Extension.ReadScripts() Extension NamedSelection_Toolbox loaded for context Mechanical.
Then I tried to modified the code, then I noticed if I just add a line like below, without any operation, the warning still shows up.
DataModel.CurrentUnitFromQuantityName
And it very strange that the same code could be run normally in mechanical scripting without any warning.
Best Answers
-
Try accessing the function CurrentUnitFromQuantityName via
ExtAPI.DataModel.CurrentUnitFromQuantityName.
Which version of Ansys are you using?
1 -
import Ansys.Mechanical.DataModel as DataModel
^--This is not the proper way to define DataModel. Instead do this:
DataModel = ExtAPI.DataModel0
Answers
-
Hi ZZ.tang!
The message 'attribute 'CurrentUnitFromQuantityName' of 'namespace#' object is read-only' means that the requested attribute is missing from the object. This can happen, for example, when using an extension developed for a different version of Ansys. Developers may remove or relocate certain attributes and functions of objects between Ansys versions. Could you provide a bit more context? Perhaps part of the code that gives this error?0 -
import clr clr.AddReference("Ans.Utilities") clr.AddReference('Ans.UI.Toolkit') clr.AddReference('Ans.UI.Toolkit.Base') clr.AddReference('System.Windows.Forms') clr.AddReference('System.Drawing') clr.AddReference('System.IO') clr.AddReference("Ansys.Mechanical.DataModel") import Ansys.Mechanical.DataModel as DataModel DataModel.CurrentUnitFromQuantityName
Something like this cannot work in ACT APP extension
but can work in scripting0 -
@ZZ.tang said:
import clr clr.AddReference("Ans.Utilities") clr.AddReference('Ans.UI.Toolkit') clr.AddReference('Ans.UI.Toolkit.Base') clr.AddReference('System.Windows.Forms') clr.AddReference('System.Drawing') clr.AddReference('System.IO') clr.AddReference("Ansys.Mechanical.DataModel") import Ansys.Mechanical.DataModel as DataModel DataModel.CurrentUnitFromQuantityName
Something like this cannot work in ACT APP extension
but can work in scriptingsorry, I just checked
the error might caused by "import Ansys.Mechanical.DataModel as DataModel"
if I runimport Ansys.Mechanical.DataModel as DataModel DataModel.CurrentUnitFromQuantityName
and then
it also not work in scriptingbut
ExtAPI.DataModel.CurrentUnitFromQuantityName
works both in APP and scripting
1