How do I remove some specific nodes with a specific name before creating new nodes of the same type? For example: if I have a node in my scene that starts with “XYZ…” then how do I programmatically remove this pre-existing node starting with XYZ . I’m trying to do this in python.
In general, you should not rely on node name to identify nodes, because node name is not guaranteed to be unique. You can use node ID instead, which is unique. You can also specify a node to be singleton, so that when you add a new instance of that node then it overwrites the previous instance in the scene instead of adding a new one. If you describe your workflow then we can recommend suitable approaches.
@lassoan i’m just trying to edit the endoscopy module so when I click create path button I only have the current paths and the previous ones get removed.
This is fixed in recent Slicer Preview Releases. Endoscopy module no longer creates new node each time you create a path, but it updates the node that is selected as “Output path”.