我想删除所有的nodes通过nodeName*
或者 slicer.util.getNodes(‘x*’), 我该咋做呢?
- 注意⚠️: 其中有同名的node
I want to delete all nodes via ‘nodeName*’ or
slicer.util.getNodes('x*')
, what should I do?
- Note⚠️: There are some nodes with the same nodeName
我想删除所有的nodes通过nodeName*
或者 slicer.util.getNodes(‘x*’), 我该咋做呢?
- 注意⚠️: 其中有同名的node
I want to delete all nodes via ‘nodeName*’ or
slicer.util.getNodes('x*')
, what should I do?
- Note⚠️: There are some nodes with the same nodeName
For this reason, I would recommend to never identify nodes by name (except for testing and debugging).
You can keep track of your nodes by storing the node object or node ID when you create the node. You can also get the list of all nodes, iterate through them and decide for each if you want to delete it.
nodes = slicer.util.getNodes(nodeName,useLists=True)
if len(nodes) == 0:
print(f"no found a node named '{nodeName}' in the scene")
return 0
else:
for key in nodes.keys():
for modNode in nodes[key]:
slicer.mrmlScene.RemoveNode(modNode)
似乎像👆🏻这样可以奏效…
Seems like those codes could work…