# Observe modified segment

**URL:** <https://discourse.slicer.org/t/observe-modified-segment/7528>\
**Category:** Development\
**Tags:** segmentation\
**Created:** [July 11, 2019, 12:15pm UTC](https://discourse.slicer.org/t/observe-modified-segment/7528 "2019-07-11T12:15:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![EricM](https://avatars.discourse-cdn.com/v4/letter/e/48db29/32.png) [@EricM](https://discourse.slicer.org/u/EricM)\
**Post date:** [July 11, 2019, 12:15pm UTC](https://discourse.slicer.org/t/observe-modified-segment/7528/1 "2019-07-11T12:15:35Z")

</div>

Hello community,  
I am trying to add an observer to a segmentation node to keep track of any modifications to any segment (by modifications I mean manual changes to the contouring). The idea is to have a marker of any modifications so if the user changes subject (for which I have a QComboBox in my module), I can prompt the user to save before changing patients. This is to avoid any accidental subject changes and losing unsaved work.

I have been trying many different things. Something close is this:

`segmentationNode = slicer.mrmlScene.AddNewNodeByClass('vtkMRMLSegmentationNode') segmentationNode.AddObserver(segmentationNode.GetSegmentation().SegmentModified,onSegmentModified)`

But this only activates onSegmentModified() when I add, remove, rename, change color of, etc… a Segment. What is the signal produced when the actual contouring changes? Is this something that can be done?  
Thanks,  
Eric

---

<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:** [July 26, 2019, 3:16am UTC](https://discourse.slicer.org/t/observe-modified-segment/7528/2 "2019-07-26T03:16:37Z")

</div>

`SegmentModified` event is invoked if segment metadata is modified. You need to observe `MasterRepresentationModified` or `RepresentationModified` to get notified about segmentation content changes. See list of events [here](https://apidocs.slicer.org/master/classvtkSegmentation.html#a1a387d4572ce52ab0c0babbecbd5a4daa82679724b676d81cd4393b6a4a388db9).

---

<div class="post-metadata">

**Author:** ![EricM](https://avatars.discourse-cdn.com/v4/letter/e/48db29/32.png) [@EricM](https://discourse.slicer.org/u/EricM)\
**Post date:** [August 5, 2019, 12:51pm UTC](https://discourse.slicer.org/t/observe-modified-segment/7528/3 "2019-08-05T12:51:38Z")

</div>

Thank you!  
This perfectly answers my question. And thank for the list of events!

Eric
