How to delete a custom object by script?
Chemsdine CHEMAI
Member, Employee Posts: 201
✭✭✭✭
Best Answer
-
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
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