# Segmentation selection changed event (custom segment editor effect)

**URL:** <https://discourse.slicer.org/t/segmentation-selection-changed-event-custom-segment-editor-effect/27856>\
**Category:** Development\
**Tags:** segmentation, python\
**Created:** [February 16, 2023, 10:43am UTC](https://discourse.slicer.org/t/segmentation-selection-changed-event-custom-segment-editor-effect/27856 "2023-02-16T10:43:08Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![lukas\_n](https://avatars.discourse-cdn.com/v4/letter/l/4da419/32.png) [@lukas\_n](https://discourse.slicer.org/u/lukas_n)\
**Post date:** [February 16, 2023, 10:43am UTC](https://discourse.slicer.org/t/segmentation-selection-changed-event-custom-segment-editor-effect/27856/1 "2023-02-16T10:43:08Z")

</div>

I am trying to write a function that is triggered when the user selects a different segmentation in the segment editor module. I searched for such event methods but could not find the right one. My guess is that there is an event for the DisplayNode of the corresponding segmentation that is triggered when selecting a different segmentation. I tried to add an observer to each segmentation node like this without success.

```python
# I tried this
segmentationNode.AddObserver(slicer.vtkMRMLSegmentationNode.SegmentationChangedEvent, self.onSegChanged)
# and this
segmentationNode.AddObserver(slicer.vtkMRMLSegmentationDisplayNode.MenuEvent, self.onSegChanged)

```

Here is a screenshot to further illustrate what I want to achieve.

![tempsnip](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/f/b/fb4b99a7700cb010136f38708c99b76aff7c5150.png)

I want to create an event method that triggers when “Segmentation\_1” is changed to a different segmentation.

Thanks for the help in advance 🙂

---

<div class="post-metadata">

**Author:** ![rajmadhan](https://avatars.discourse-cdn.com/v4/letter/r/5daacb/32.png) [@rajmadhan](https://discourse.slicer.org/u/rajmadhan)\
**Post date:** [March 26, 2024, 10:38pm UTC](https://discourse.slicer.org/t/segmentation-selection-changed-event-custom-segment-editor-effect/27856/2 "2024-03-26T22:38:51Z")

</div>

Hi Lukas,  
Do you by any chance able to find a solution for this problem?

---

<div class="post-metadata">

**Author:** ![lukas\_n](https://avatars.discourse-cdn.com/v4/letter/l/4da419/32.png) [@lukas\_n](https://discourse.slicer.org/u/lukas_n)\
**Post date:** [March 28, 2024, 12:35pm UTC](https://discourse.slicer.org/t/segmentation-selection-changed-event-custom-segment-editor-effect/27856/3 "2024-03-28T12:35:29Z")

</div>

Hello Raj,  
thanks for your reply, sadly I don’t work on this project anymore… I could not find a solution for this, but the problem was not that critical. It was a nice-to-have feature of the slicer plugin I made. 🙂

---

<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:** [March 28, 2024, 3:42pm UTC](https://discourse.slicer.org/t/segmentation-selection-changed-event-custom-segment-editor-effect/27856/4 "2024-03-28T15:42:53Z")

</div>

You can use the [segmentationNodeChanged](https://apidocs.slicer.org/master/classqMRMLSegmentEditorWidget.html#a4df0865783eaabce916723c830f3f287) signal of the segment editor widget.

---

<div class="post-metadata">

**Author:** ![rajmadhan](https://avatars.discourse-cdn.com/v4/letter/r/5daacb/32.png) [@rajmadhan](https://discourse.slicer.org/u/rajmadhan)\
**Post date:** [April 1, 2024, 10:09pm UTC](https://discourse.slicer.org/t/segmentation-selection-changed-event-custom-segment-editor-effect/27856/5 "2024-04-01T22:09:09Z")

</div>

Thanks for the reply.  
I found the solution based on @lassoan Andras Lasso response.

---

<div class="post-metadata">

**Author:** ![rajmadhan](https://avatars.discourse-cdn.com/v4/letter/r/5daacb/32.png) [@rajmadhan](https://discourse.slicer.org/u/rajmadhan)\
**Post date:** [April 1, 2024, 10:13pm UTC](https://discourse.slicer.org/t/segmentation-selection-changed-event-custom-segment-editor-effect/27856/6 "2024-04-01T22:13:24Z")

</div>

Hi @lassoan Andras Lasso,  
Thanks for your response.  
[segmentationNodeChanged](https://apidocs.slicer.org/master/classqMRMLSegmentEditorWidget.html#a4df0865783eaabce916723c830f3f287) signal didn’t work for my problem. This sends the signal when ever I changed the segmentation node, i.e., when a new image is loaded.  
[currentSegmentIDChanged](https://apidocs.slicer.org/master/classqMRMLSegmentEditorWidget.html#a9172bd5ffebecf7f8f71da4faddc9ace) worked as I expected. This sends the signal whenever I change selection of the segment in the segment editor widget.
