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

**URL:** <https://discourse.slicer.org/t/how-to-delete-nodes-from-scene-before-creating-new-nodes-with-the-same-name/16220>\
**Category:** Development\
**Created:** [February 25, 2021, 6:31pm UTC](https://discourse.slicer.org/t/how-to-delete-nodes-from-scene-before-creating-new-nodes-with-the-same-name/16220 "2021-02-25T18:31:02Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![akshay\_pillai](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/akshay_pillai/32/8301_2.png) [@akshay\_pillai](https://discourse.slicer.org/u/akshay_pillai)\
**Post date:** [February 25, 2021, 6:31pm UTC](https://discourse.slicer.org/t/how-to-delete-nodes-from-scene-before-creating-new-nodes-with-the-same-name/16220/1 "2021-02-25T18:31:02Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Alex\_Vergara](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/alex_vergara/32/15205_2.png) [@Alex\_Vergara](https://discourse.slicer.org/u/Alex_Vergara)\
**Post date:** [February 25, 2021, 6:37pm UTC](https://discourse.slicer.org/t/how-to-delete-nodes-from-scene-before-creating-new-nodes-with-the-same-name/16220/2 "2021-02-25T18:37:32Z")

</div>

I have lots of examples in my code on how to achieve this. Just watch [Dosimetry4D/Logic/Dosimetry4DLogic.py · develop · OpenDose / SlicerOpenDose3D · GitLab](https://gitlab.com/opendose/opendose3d/-/blob/develop/Dosimetry4D/Logic/Dosimetry4DLogic.py#L465)

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [February 25, 2021, 6:39pm UTC](https://discourse.slicer.org/t/how-to-delete-nodes-from-scene-before-creating-new-nodes-with-the-same-name/16220/3 "2021-02-25T18:39:57Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![akshay\_pillai](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/akshay_pillai/32/8301_2.png) [@akshay\_pillai](https://discourse.slicer.org/u/akshay_pillai)\
**Post date:** [February 25, 2021, 7:09pm UTC](https://discourse.slicer.org/t/how-to-delete-nodes-from-scene-before-creating-new-nodes-with-the-same-name/16220/4 "2021-02-25T19:09:27Z")

</div>

> [@lassoan](#):
>
> ibe your workflow then we c

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

---

<div class="post-metadata">

**Author:** ![akshay\_pillai](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/akshay_pillai/32/8301_2.png) [@akshay\_pillai](https://discourse.slicer.org/u/akshay_pillai)\
**Post date:** [February 25, 2021, 7:11pm UTC](https://discourse.slicer.org/t/how-to-delete-nodes-from-scene-before-creating-new-nodes-with-the-same-name/16220/5 "2021-02-25T19:11:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [February 25, 2021, 7:11pm UTC](https://discourse.slicer.org/t/how-to-delete-nodes-from-scene-before-creating-new-nodes-with-the-same-name/16220/6 "2021-02-25T19:11:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![akshay\_pillai](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/akshay_pillai/32/8301_2.png) [@akshay\_pillai](https://discourse.slicer.org/u/akshay_pillai)\
**Post date:** [February 25, 2021, 7:13pm UTC](https://discourse.slicer.org/t/how-to-delete-nodes-from-scene-before-creating-new-nodes-with-the-same-name/16220/7 "2021-02-25T19:13:34Z")

</div>

ok, I’ll check that out.
