# Multiple segment

**URL:** https://discourse.slicer.org/t/multiple-segment/2493
**Category:** Development
**Created:** [April 2, 2018, 2:53pm UTC](https://discourse.slicer.org/t/multiple-segment/2493 "2018-04-02T14:53:35Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![anandmulay3](https://avatars.discourse-cdn.com/v4/letter/a/ac8455/32.png) [@anandmulay3](https://discourse.slicer.org/u/anandmulay3)
#### Post date: [April 2, 2018, 2:53pm UTC](https://discourse.slicer.org/t/multiple-segment/2493/1 "2018-04-02T14:53:35Z")

</div>

i’m adding 2nd segment under same masterNode, But whenever i try to apply effects on it’s getting applied on 1st segment only,  
How to select 2nd segment as active segment???

---

<div class="post-metadata">

### Author: ![cpinter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cpinter/32/7995_2.png) [@cpinter](https://discourse.slicer.org/u/cpinter)
#### Post date: [April 2, 2018, 4:05pm UTC](https://discourse.slicer.org/t/multiple-segment/2493/2 "2018-04-02T16:05:23Z")

</div>

You need to select the second segment in the segment list. It’s always the highlighted one that is edited by the selected effect.

---

<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: [April 2, 2018, 5:23pm UTC](https://discourse.slicer.org/t/multiple-segment/2493/3 "2018-04-02T17:23:48Z")

</div>

Programmetically you can select a segment using [setCurrentSegmentID](http://apidocs.slicer.org/master/classqMRMLSegmentEditorWidget.html#a1537f275ab7571d8b330dfb5afdfe5ed) method of the segment editor widget.

---

<div class="post-metadata">

### Author: ![anandmulay3](https://avatars.discourse-cdn.com/v4/letter/a/ac8455/32.png) [@anandmulay3](https://discourse.slicer.org/u/anandmulay3)
#### Post date: [April 3, 2018, 1:21pm UTC](https://discourse.slicer.org/t/multiple-segment/2493/4 "2018-04-03T13:21:55Z")

</div>

addsegID = segmentationNode.GetSegmentation().AddEmptySegment(“bone”)  
segmentEditorWidget = slicer.qMRMLSegmentEditorWidget()  
segmentEditorWidget.setMRMLScene(slicer.mrmlScene)  
segmentEditorNode = slicer.mrmlScene.AddNewNodeByClass(“vtkMRMLSegmentEditorNode”)  
segmentEditorWidget.setMRMLSegmentEditorNode(segmentEditorNode)  
segmentEditorWidget.setSegmentationNode(segmentationNode)  
segmentEditorWidget.setMasterVolumeNode(masterVolumeNode)  
segmentEditorWidget.setCurrentSegmentID(‘addsegID’)  
segmentEditorWidget.setActiveEffectByName(“Threshold”)  
Traceback (most recent call last):  
File “C:\Program Files\Slicer 4.9.0-2018-03-27\lib\Slicer-4.9\qt-scripted-modules\SegmentEditorEffects\SegmentEditorEffects\SegmentEditorThresholdEffect.py”, line 54, in activate  
self.segment2DFillOpacity = displayNode.GetSegmentOpacity2DFill(segmentID)  
TypeError: GetSegmentOpacity2DFill argument 1: string is required

i’m getting this error when i try to switch on 2nd segment to apply effect

---

<div class="post-metadata">

### Author: ![cpinter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cpinter/32/7995_2.png) [@cpinter](https://discourse.slicer.org/u/cpinter)
#### Post date: [April 3, 2018, 3:17pm UTC](https://discourse.slicer.org/t/multiple-segment/2493/5 "2018-04-03T15:17:49Z")

</div>

Based on the code snippet you posted there is no variable named `segmentID`, so getting the error is expected. You have one variable storing a segment ID called `addsegID`. Maybe you wanted to use that?

---

<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: [April 3, 2018, 10:23pm UTC](https://discourse.slicer.org/t/multiple-segment/2493/6 "2018-04-03T22:23:07Z")

</div>

> [@anandmulay3](#):
>
> segmentEditorWidget.setCurrentSegmentID(‘addsegID’)

Another issue is that here you probably wanted to set the string that is stored in addSegID variable, so the quotes around addSegID must be removed.

---

<div class="post-metadata">

### Author: ![anandmulay3](https://avatars.discourse-cdn.com/v4/letter/a/ac8455/32.png) [@anandmulay3](https://discourse.slicer.org/u/anandmulay3)
#### Post date: [April 4, 2018, 7:42am UTC](https://discourse.slicer.org/t/multiple-segment/2493/7 "2018-04-04T07:42:44Z")

</div>

ohh yes that was the fault, thanks
