# Control point modified event is not fired

**URL:** <https://discourse.slicer.org/t/control-point-modified-event-is-not-fired/39783>\
**Category:** Development\
**Created:** [October 21, 2024, 8:28pm UTC](https://discourse.slicer.org/t/control-point-modified-event-is-not-fired/39783 "2024-10-21T20:28:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mau\_igna\_06](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mau_igna_06/32/9056_2.png) [@mau\_igna\_06](https://discourse.slicer.org/u/mau_igna_06)\
**Post date:** [October 21, 2024, 8:28pm UTC](https://discourse.slicer.org/t/control-point-modified-event-is-not-fired/39783/1 "2024-10-21T20:28:37Z")

</div>

Hi,

I think I’ve found a bug:

```auto
lineNode = slicer.mrmlScene.CreateNodeByClass("vtkMRMLMarkupsLineNode")
slicer.mrmlScene.AddNode(lineNode)
slicer.modules.markups.logic().AddNewDisplayNodeForMarkupsNode(lineNode)
lineNode.SetName("myLineNode")

observerTag = lineNode.AddObserver(
    slicer.vtkMRMLMarkupsNode.PointModifiedEvent,
    lambda arg1,arg2: print("Point modified")
)

# does print
lineNode.AddControlPoint(vtk.vtkVector3d(0,0,0))
# does print
lineNode.AddControlPoint(vtk.vtkVector3d(50,50,50))

for i in range(lineNode.GetNumberOfControlPoints()):
    # doesn't print but it should
    lineNode.RemoveNthControlPoint(0) 

```

Maybe I’m doing something wrong, please explain

Best wishes,  
Mauro

---

<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:** [October 22, 2024, 12:02am UTC](https://discourse.slicer.org/t/control-point-modified-event-is-not-fired/39783/2 "2024-10-22T00:02:20Z")

</div>

We try to invoke a `PointModifiedEvent` whenever it is possible to reduce the number of events that modules have to observe. However, in case of deleting a point it would not be clear if the point id refers to the point that was removed or to the point that was moved to the removed point’s position. Instead, `vtkMRMLMarkupsNode::PointAboutToBeRemovedEvent` and `vtkMRMLMarkupsNode::PointRemovedEvent` events are invoked with the removed point’s index.

I can see that this behavior may seem inconsistent and it may be inconvenient that you need to observe an additional event, so let me know if you think it would help you if different events were invoked. It would not be a problem at all to invoke a `PointModifiedEvent` with the removed point’s index if that would greatly simplify your code.

---

<div class="post-metadata">

**Author:** ![mau\_igna\_06](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mau_igna_06/32/9056_2.png) [@mau\_igna\_06](https://discourse.slicer.org/u/mau_igna_06)\
**Post date:** [October 22, 2024, 12:10am UTC](https://discourse.slicer.org/t/control-point-modified-event-is-not-fired/39783/3 "2024-10-22T00:10:50Z")

</div>

I tried doing something like:

```auto
observerTag = lineNode.AddObserver(
    slicer.vtkMRMLMarkupsNode.PointModifiedEvent | slicer.vtkMRMLMarkupsNode.PointRemovedEvent,
    lambda arg1,arg2: print("Point modified")
)

```

But it did not work.  
I don’t mind another observer for the moment

---

<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:** [October 22, 2024, 12:53am UTC](https://discourse.slicer.org/t/control-point-modified-event-is-not-fired/39783/4 "2024-10-22T00:53:26Z")

</div>

The result of `slicer.vtkMRMLMarkupsNode.PointModifiedEvent | slicer.vtkMRMLMarkupsNode.PointRemovedEvent` operation is some number that probably does not correspond to any event ID. You need to add and remove each observer separately.

---

<div class="post-metadata">

**Author:** ![Abhishek\_Markad](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/abhishek_markad/32/77799_2.png) [@Abhishek\_Markad](https://discourse.slicer.org/u/Abhishek_Markad)\
**Post date:** [November 4, 2024, 10:29am UTC](https://discourse.slicer.org/t/control-point-modified-event-is-not-fired/39783/5 "2024-11-04T10:29:23Z")

</div>

how to access control point index in invoked function.

Below is the python snippet,is it right way?

```auto
pointListNode = slicer.mrmlScene.AddNewNodeByClass(
            "vtkMRMLMarkupsFiducialNode"
        )
pointListNode.AddObserver(slicer.vtkMRMLMarkupsNode.PointAboutToBeRemovedEvent,on_point_to_be_removed)
def on_point_to_be_removed(caller,event):
        markupsNode = caller
        sliceView = markupsNode.GetAttribute("Markups.MovingInSliceView")
        movingMarkupIndex = markupsNode.GetDisplayNode().GetActiveControlPoint()
        print(movingMarkupIndex)
        label=markupsNode.GetNthControlPointLabel(movingMarkupIndex)

```

Output:  
-1  
GUI used to remove the control point.

 ![delete_control_point](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/2/7/27faad684eaa6d4fb20f8d1933c30a60fc4611bf.jpeg)

I want to access label of control point to be removed.  
Thank you.

---

<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:** [November 5, 2024, 2:38pm UTC](https://discourse.slicer.org/t/control-point-modified-event-is-not-fired/39783/6 "2024-11-05T14:38:35Z")

</div>

I don’t have any working example but I think you need to define the callback function like this:

```auto
@vtk.calldata_type(vtk.VTK_INT)
def onPointAboutToBeRemoved(self, caller, eventId, callData):

```

The `callData` will be the point index. `self` obviously is only needed if the callback is a member function.
