How to delete nodes from scene before creating new nodes with the same name?

Operating system:Windows 11
Slicer version:4.11.20200930

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.

I have lots of examples in my code on how to achieve this. Just watch Dosimetry4D/Logic/Dosimetry4DLogic.py · develop · OpenDose / SlicerOpenDose3D · GitLab

1 Like

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.

1 Like

@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.

@Alex_Vergara Thanks, I’ll take a look at this.

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”.

1 Like

ok, I’ll check that out.

Great and useful information, thanks! :+1:

1 Like

I appreciate your work guys and the answers in this topic. Great and useful information, thanks! :+1:

1 Like