# Input segments in new module

**URL:** <https://discourse.slicer.org/t/input-segments-in-new-module/5064>\
**Category:** Development\
**Tags:** module\
**Created:** [December 12, 2018, 11:10pm UTC](https://discourse.slicer.org/t/input-segments-in-new-module/5064 "2018-12-12T23:10:37Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![ThomPote](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/thompote/32/2256_2.png) [@ThomPote](https://discourse.slicer.org/u/ThomPote)\
**Post date:** [December 12, 2018, 11:10pm UTC](https://discourse.slicer.org/t/input-segments-in-new-module/5064/1 "2018-12-12T23:10:37Z")

</div>

Hi,

I’m trying to create a new module.

I can select differents nodes like Volume and Segmentation node as input.

But how can I select my different segments in Segmentation as input before running the analyse with apply button ?

Thanks for all

---

<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:** [December 12, 2018, 11:15pm UTC](https://discourse.slicer.org/t/input-segments-in-new-module/5064/2 "2018-12-12T23:15:09Z")

</div>

Is your module C++ or Python?

---

<div class="post-metadata">

**Author:** ![ThomPote](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/thompote/32/2256_2.png) [@ThomPote](https://discourse.slicer.org/u/ThomPote)\
**Post date:** [December 12, 2018, 11:38pm UTC](https://discourse.slicer.org/t/input-segments-in-new-module/5064/3 "2018-12-12T23:38:37Z")

</div>

Only in Python for the moment

Thanks

---

<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:** [December 12, 2018, 11:49pm UTC](https://discourse.slicer.org/t/input-segments-in-new-module/5064/4 "2018-12-12T23:49:59Z")

</div>

We don’t have a widget for that just yet. But we have examples. Please follow this variable through this code and you can easily replicate it:

> <https://github.com/SlicerRt/SegmentRegistration/blob/master/SegmentRegistration/SegmentRegistration.py#L81>

---

<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:** [December 13, 2018, 12:24am UTC](https://discourse.slicer.org/t/input-segments-in-new-module/5064/5 "2018-12-13T00:24:30Z")

</div>

@cpinter you’ve implemented a segment selector widget - _qMRMLSegmentSelectorWidget_ - which includes a segmentation node selector and a segment selector combobox:

```auto
sw=slicer.qMRMLSegmentSelectorWidget()
sw.setMRMLScene(slicer.mrmlScene)
sw.setCurrentNode(getNode('Segmentation'))
sw.show()

```

![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/b/a/ba560a18125760647b06393241c1cf7b94633576.png)

For selecting multiple segments, you can use _qMRMLSegmentsTableView_ (you need to add a segmentation node selector separately):

```auto
st=slicer.qMRMLSegmentsTableView()
st.setMRMLScene(slicer.mrmlScene)
st.setSegmentationNode(getNode('Segmentation'))
st.show()

```

![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/d/c/dc695ae62274f06633dfe155eab6691e91b49b36.png)

---

<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:** [December 13, 2018, 2:42am UTC](https://discourse.slicer.org/t/input-segments-in-new-module/5064/6 "2018-12-13T02:42:58Z")

</div>

Wow you’re right 🙂 Not sure why I still have the old way in those python modules. Thanks for remembering better what I did than myself 🙂

---

<div class="post-metadata">

**Author:** ![Saima](https://avatars.discourse-cdn.com/v4/letter/s/9d8465/32.png) [@Saima](https://discourse.slicer.org/u/Saima)\
**Post date:** [September 12, 2021, 1:55am UTC](https://discourse.slicer.org/t/input-segments-in-new-module/5064/7 "2021-09-12T01:55:40Z")

</div>

Hi Andras,  
How can I get the selected segment using the selectorwidgot using python script.

I get the segmentationNode but how can I get the selected segment from the qmrmlsegmentselectorwidget

regards,

Saima Safdar

---

<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:** [September 12, 2021, 2:10am UTC](https://discourse.slicer.org/t/input-segments-in-new-module/5064/8 "2021-09-12T02:10:39Z")

</div>

Have you tried to use the [selectedSegmentIDs](https://apidocs.slicer.org/master/classqMRMLSegmentsTableView.html#a0c20e258ba22fcd494a96829e0ddb146) method?

---

<div class="post-metadata">

**Author:** ![Saima](https://avatars.discourse-cdn.com/v4/letter/s/9d8465/32.png) [@Saima](https://discourse.slicer.org/u/Saima)\
**Post date:** [September 12, 2021, 4:24am UTC](https://discourse.slicer.org/t/input-segments-in-new-module/5064/9 "2021-09-12T04:24:15Z")

</div>

no I cannot use it with segmentationNode.

Do you have any example where the qMRMLsegmentselectorwidget is used.

Thankyou for sharing

regards,  
Saima Safdar

---

<div class="post-metadata">

**Author:** ![Saima](https://avatars.discourse-cdn.com/v4/letter/s/9d8465/32.png) [@Saima](https://discourse.slicer.org/u/Saima)\
**Post date:** [September 12, 2021, 4:49am UTC](https://discourse.slicer.org/t/input-segments-in-new-module/5064/10 "2021-09-12T04:49:52Z")

</div>

Hi Andras,  
Thank you for the feedback. I found how to connect the widget in scripted module.

Reagrds,  
Saima Safdar

---

<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:** [September 12, 2021, 11:44am UTC](https://discourse.slicer.org/t/input-segments-in-new-module/5064/11 "2021-09-12T11:44:11Z")

</div>

> [@Saima](#):
>
> Thank you for the feedback. I found how to connect the widget in scripted module.

If you find out anything non-obvious then please share it here so that others who run into this can find the solution (and we may also use the information to improve the documentation).

---

<div class="post-metadata">

**Author:** ![Saima](https://avatars.discourse-cdn.com/v4/letter/s/9d8465/32.png) [@Saima](https://discourse.slicer.org/u/Saima)\
**Post date:** [September 13, 2021, 4:12am UTC](https://discourse.slicer.org/t/input-segments-in-new-module/5064/12 "2021-09-13T04:12:19Z")

</div>

Yes I will share on github and provide link here.

---

<div class="post-metadata">

**Author:** ![RafaelPalomar](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rafaelpalomar/32/1436_2.png) [@RafaelPalomar](https://discourse.slicer.org/u/RafaelPalomar)\
**Post date:** [September 19, 2024, 6:31am UTC](https://discourse.slicer.org/t/input-segments-in-new-module/5064/13 "2024-09-19T06:31:50Z")

</div>

Hello. I’m looking for a more compact widget for selecting multiple segments and I found this post. I was wondering if there is a more recent approach for segments selection that can easily be integrated in other modules. Thanks.

---

<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:** [September 19, 2024, 11:34am UTC](https://discourse.slicer.org/t/input-segments-in-new-module/5064/14 "2024-09-19T11:34:03Z")

</div>

If you need to select multiple segments then I would recommend the qMRMLSegmentsTableView. This widget has filter&search capabilities that are essential if you need to work with a segmentation that contains many segments (common with automatic segmentation tools).

Alternatively, you can use the qMRMLSegmentSelectorWidget to select a segment and an “add” button to add it to a list, and “remove” button for each added segment to remove them. This may take up a bit less space, but it is more work to implement.

You can also do without any segment selection and say that you work with all visible segments; or all flagged segments (you can set status of a segment in the segment list by right-clicking and choosing “Show filter bar”).

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/d/f/df7ccdb9bccf260b9cea5fd4b08ea2612fb2cb2e.png)
