Howto delete all nodes by '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
  for key in nodes.keys():
    for modNode in nodes[key]:


Seems like :point_up_2:t2: those codes could work…