Is there any callback for the mouse click when adding a new markup?

Hello, I am developing a new application for 3D Slicer, however I cannot find a resolution to my problem. I am running a way to add control points via mouse click, the way I found in the repository script.

selectionNode = slicer.mrmlScene.GetNodeByID("vtkMRMLSelectionNodeSingleton")
selectionNode.SetReferenceActivePlaceNodeClassName("vtkMRMLMarkupsFiducialNode")
interactionNode = slicer.mrmlScene.GetNodeByID("vtkMRMLInteractionNodeSingleton")
placeModePersistence = 1
interactionNode.SetPlaceModePersistence(placeModePersistence)
# mode 1 is Place, can also be accessed via slicer.vtkMRMLInteractionNode().Place
interactionNode.SetCurrentInteractionMode(1)

Would it be possible to associate some callback for when a new control point is added?
Thank you all for your attention.

I think you’re looking for the PointPositionDefinedEvent. slicer.vtkMRMLMarkupsNode.PointPositionDefinedEvent

https://apidocs.slicer.org/main/classvtkMRMLMarkupsNode.html#aceeef8806df28e3807988c38510e56caaf1067cd7bcb1bd0992112b22daf219d5

1 Like

It’s worked, thank you!!
I made a new function:

def AddNewMarkup(self, caller, event):
        markupsNode = caller
        sliceView = markupsNode.GetAttribute("Markups.PointPositionDefinedEvent")
        movingMarkupIndex = markupsNode.GetDisplayNode().GetActiveControlPoint()
        addingMarkup = slicer.vtkMRMLMarkupsNode.PointAddedEvent 
        if addingMarkup >= 0:
            newMarkup = f"fiducial_{movingMarkupIndex+1}"
            self.mMarkupid.addItem(newMarkup)
            self.mMarkupid.setCurrentIndex(movingMarkupIndex)
        else:
            self.interactionNode.SetCurrentInteractionMode(0)

and I call it by:
self.tnode.AddObserver(slicer.vtkMRMLMarkupsNode.PointPositionDefinedEvent, self.AddNewMarkup)