# How to rename segments in a segmentation node?

**URL:** <https://discourse.slicer.org/t/how-to-rename-segments-in-a-segmentation-node/16575>\
**Category:** Development\
**Tags:** python\
**Created:** [March 16, 2021, 2:47pm UTC](https://discourse.slicer.org/t/how-to-rename-segments-in-a-segmentation-node/16575 "2021-03-16T14:47:56Z")\
**Posts on this page:** 6\
**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:** [March 16, 2021, 2:47pm UTC](https://discourse.slicer.org/t/how-to-rename-segments-in-a-segmentation-node/16575/1 "2021-03-16T14:47:57Z")

</div>

Operating system: Windows 10  
Slicer version:4.11  
How can I change the names of segments in a segmentation. I can do this manually in the GUI but I want to know if there is any way to do this programmatically. I can’t see any mrml node ids for each individual segment.

---

<div class="post-metadata">

**Author:** ![Sunderlandkyl](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/sunderlandkyl/32/79987_2.png) [@Sunderlandkyl](https://discourse.slicer.org/u/Sunderlandkyl)\
**Post date:** [March 16, 2021, 3:42pm UTC](https://discourse.slicer.org/t/how-to-rename-segments-in-a-segmentation-node/16575/2 "2021-03-16T15:42:35Z")

</div>

There are no nodes for individual segments. The segmentation node has a vtkSegmentation object which holds all of the segments.

You can get a segmentation from the segmentation node, and change the name like this:

```auto
segmentation = segmentationNode.GetSegmentation()
segment = segmentation.GetNthSegment(0)
segment.SetName("NewName")

```

vtkSegmentation doc: [Slicer: vtkSegmentation Class Reference](https://apidocs.slicer.org/master/classvtkSegmentation.html)  
vtkSegment doc: [Slicer: vtkSegment Class Reference](https://apidocs.slicer.org/master/classvtkSegment.html)

---

<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:** [March 19, 2021, 1:44pm UTC](https://discourse.slicer.org/t/how-to-rename-segments-in-a-segmentation-node/16575/4 "2021-03-19T13:44:55Z")

</div>

@Sunderlandkyl Hey, thanks. Could you also tell me if there is a way to setname for vtkSegmentation and not just vtkSegment?

---

<div class="post-metadata">

**Author:** ![Sunderlandkyl](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/sunderlandkyl/32/79987_2.png) [@Sunderlandkyl](https://discourse.slicer.org/u/Sunderlandkyl)\
**Post date:** [March 19, 2021, 3:29pm UTC](https://discourse.slicer.org/t/how-to-rename-segments-in-a-segmentation-node/16575/5 "2021-03-19T15:29:11Z")

</div>

If you are trying to change the name of the entire segmentation node, you can use:

```auto
segmentationNode.SetName("NewName")

```

---

<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:** [March 19, 2021, 3:33pm UTC](https://discourse.slicer.org/t/how-to-rename-segments-in-a-segmentation-node/16575/6 "2021-03-19T15:33:35Z")

</div>

@Sunderlandkyl thanks again. Sorry for asking again and again but Similarly, if I have other types of nodes like markupcurvesnode but not one but multiple and want to change there names , how would I access each to set names?

---

<div class="post-metadata">

**Author:** ![Sunderlandkyl](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/sunderlandkyl/32/79987_2.png) [@Sunderlandkyl](https://discourse.slicer.org/u/Sunderlandkyl)\
**Post date:** [March 19, 2021, 3:35pm UTC](https://discourse.slicer.org/t/how-to-rename-segments-in-a-segmentation-node/16575/7 "2021-03-19T15:35:40Z")

</div>

The name of every node can be changed with the SetName method.
