How to delete a custom object by script?
Best Answers
-
By using the customization API to retrieve the object, i.e :
currentobj=ExtAPI.DataModel.GetUserObjects(ExtAPI.ExtensionManager.CurrentExtension)[0]
One will not see any
Delete()
function accessible.The trick is to use the Automation API, for example :
automcurrentobj=ExtAPI.DataModel.GetObjectById(currentobj.ObjectId) automcurrentobj.Delete()
from the 2021R1, you can use instead of "automcurrentobj.Delete()" :
DS = ExtAPI.DataModel.InternalObject["ds"] DS.Tree.DeleteObject(automcurrentobj.ObjectId)
1 -
@Jean Use the
DeleteObject
function that I posted previously.Alternatively, add parentheses to DS.Tree for 24.2:
DS.Tree().DeleteObject(automcurrentobj.ObjectId)
0
Answers
-
Hello Chemsdine,
The code works:
currentobj=ExtAPI.DataModel.GetUserObjects(ExtAPI.ExtensionManager.Extensions[0])[0] automcurrentobj=ExtAPI.DataModel.GetObjectById(currentobj.ObjectId) DS = ExtAPI.DataModel.InternalObject["ds"] DS.Tree.DeleteObject(automcurrentobj.ObjectId)
Here, the current extension is selected by its index in the list of loaded extensions. Then, the target user object is selected and deleted. The only thing that causes doubt is the use of InternalObject. As I know it is recommended only as a last resort.
Thanks
0 -
def DeleteObject(obj): try: ID = obj.ObjectId except: ID = obj.InternalObject.ID JScmds = 'DS.Tree.DeleteObject({})'.format(ID) ExtAPI.Application.ScriptByName("jscript").ExecuteCommand(JScmds)
0 -
@dafedin said:
Hello Chemsdine,The code works:
currentobj=ExtAPI.DataModel.GetUserObjects(ExtAPI.ExtensionManager.Extensions[0])[0] automcurrentobj=ExtAPI.DataModel.GetObjectById(currentobj.ObjectId) DS = ExtAPI.DataModel.InternalObject["ds"] DS.Tree.DeleteObject(automcurrentobj.ObjectId)
Here, the current extension is selected by its index in the list of loaded extensions. Then, the target user object is selected and deleted. The only thing that causes doubt is the use of InternalObject. As I know it is recommended only as a last resort.
Thanks
Hi,
This code works perfectly in Ansys 22R2, but in Ansys 24R2, there is an error :
'DispCallable' object has no attribute 'DeleteObject'
Is there a new way to do that ?
Regards,
Jean0