JJM Posted February 29, 2016 Share Posted February 29, 2016 Hi! How to use Node.destroy() method? If we define something like this: def delSearch(patt): for n in hou.node('/obj/').allSubChildren(): if n.name().startswith(patt): print (n.path()) n.destroy() Then call it: hou.session.delSearch("rozo") Houdini prints one node name and removes this node. But then reports error: >>> hou.session.delSearch("rozo") /obj/rozok26 Traceback (most recent call last): File "<console>", line 1, in <module> File "hou.session", line 3, in delSearch File "/opt/hfs15.0.347/houdini/python2.7libs/hou.py", line 5140, in name return _hou.Node_name(*args) ObjectWasDeleted: Attempt to access an object that no longer exists in Houdini. What can i do to delete all nodes with same name pattern? This case is described in documentation but i can't find a way to resolve this problem. Quote Link to comment Share on other sites More sharing options...
Atom Posted February 29, 2016 Share Posted February 29, 2016 (edited) Maybe it is because you are modifying the list you are iterating over? Instead of deleting inside the loop, consider collecting names to delete in a second pass. def delSearch(patt): results = [] for n in hou.node('/obj/').allSubChildren(): if n.name().startswith(patt): print (n.path()) results.append(n.path()) if len(results): for node_name in results: hou.node(node_name).destroy() hou.session.delSearch("rozo") Edited February 29, 2016 by Atom Quote Link to comment Share on other sites More sharing options...
JJM Posted February 29, 2016 Author Share Posted February 29, 2016 (edited) it's doesn't work. def delSearch(patt): results = [] for n in hou.node('/obj/').allSubChildren(): if n.name().startswith(patt): print (n.path()) results.append(n.path()) print (len(results)) if len(results): for node_name in results: hou.node(node_name).destroy() output: hou.session.delSearch("Arch") /obj/Arch41_052_obj_20 ..... /obj/Arch41_052_obj_7 /obj/Arch41_052_obj_7/Arch41_052_obj_7 /obj/Arch41_052_obj_19 /obj/Arch41_052_obj_19/Arch41_052_obj_19 30 Traceback (most recent call last): File "<console>", line 1, in <module> File "hou.session", line 11, in delSearch AttributeError: 'function' object has no attribute 'destroy' something wrong... Edited February 29, 2016 by JJM Quote Link to comment Share on other sites More sharing options...
lukeiamyourfather Posted February 29, 2016 Share Posted February 29, 2016 Is it deleting the parent and then can't find the child? It looks like there are children with the same pattern in their name. The proper way if that's the case would be to get a new list of nodes each time one is deleted until none are left (while loop). Quote Link to comment Share on other sites More sharing options...
michael Posted March 1, 2016 Share Posted March 1, 2016 if you have /obj/Arch41_052_obj_20...../obj/Arch41_052_obj_7 don't use subChildren() - that will search recursively through the entire file and find things like /obj/Arch41_052_obj_7/Arch41_052_obj_7 just use for child in node.children() that will get all the nodes at the /obj/ level /obj/Arch41_052_obj_7 etc Quote Link to comment Share on other sites More sharing options...
JJM Posted March 1, 2016 Author Share Posted March 1, 2016 (edited) Thanks for the help.this code works fine: def delSearch(patt): results = [] for n in hou.node('/obj/').children(): if n.name().startswith(patt): print (n.path()) results.append(n.path()) print (len(results)) if len(results): for node_name in results: hou.node(node_name).destroy() Edited March 1, 2016 by JJM 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.