How to remove command snippet ?
Hi,
I am trying to adapt a script presented by @Pernelle Marone-Hitz : https://developer.ansys.com/blog/script-tip-friday-efficiently-combining-mapdl-and-mechanical-scripting?check_logged_in=1
Before command snippet are created which I give the name "command_snippet_joint_ID", I would like to check if a command snippet already exist with this name. If yes, I would like to delete the command and then add the new one. If no (or if a command snippet with another name exist), just add the new one.
Is it possible to do this king of check ?
Regards,
Jean
Best Answer
-
for existing in ExtAPI.DataModel.GetObjectsByName('delete_me') and ExtAPI.DataModel.GetObjectsByType(Ansys.ACT.Automation.Mechanical.CommandSnippet): existing.Delete()
0
Answers
-
You can do something like this.
In general I would recommend an easier solution to use the property "Element APDL Name" for the joints. Here you can set a custom variable name for the joints. You can automate that this property be set to "Joint_" so that it is unique and traceable back to the mechanical object. This bypasses the command snippet all together and keeps things easier if all you want is to store Ids for post.
You lastly could implement python code objects in the post section and use the Solution.SolverData to dynamically get the Ids after the solution is run, bypassing any pre-processing required.
SnipName = 'command_snippet_joint_ID'
def GetSnippets(Joint, Name):
Snippets = Joint.GetChildren(DataModelObjectCategory.CommandSnippet, True)
Snippets=filter(lambda Obj: Obj.Name==Name, Snippets)
return Snippets
for Joint in ExtAPI.DataModel.GetObjectsByType(DataModelObjectCategory.Joint):
Snippets = GetSnippets(MyJoint, SnipName)
print Joint.Name+": # of Cmd Snippets: "+str(len(Snippets))0 -
Thanks for your answers!
0