Markup notification

Hi, I am testing out the repository script “Get a notification if a markup point position is modified”. It is working (stuff being printed in python console) in Slicer 4.10.1, but I am getting no notifications in the version I just compiled early this week. Any idea what is going on?

Below is the script.

def onMarkupsNodeModified(markupsNode, unusedArg2=None, unusedArg3=None):
  sliceView = markupsNode.GetAttribute('Markups.MovingInSliceView')
  if not sliceView:
    print("Markup list was modified")
    return
  movingMarkupIndex = markupsNode.GetAttribute('Markups.MovingMarkupIndex')
  pos = [0,0,0]
  markupsNode.GetNthFiducialPosition(int(movingMarkupIndex), pos)  
  print("Markup {0} was moved in slice view {1} to {2}".format(movingMarkupIndex, sliceView, pos))

markupsNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLMarkupsFiducialNode")
markupsNode.CreateDefaultDisplayNodes()
markupsNode.AddFiducial(0,0,0)
markupsNode.AddObserver(vtk.vtkCommand.ModifiedEvent, onMarkupsNodeModified)

I see that the wiki ScriptRepository might have some outdated examples as you are referring to.
https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Get_a_notification_if_a_markup_point_position_is_modified
@lassoan Do you mind updating these examples for the nightly documentation wiki pages?

Markups has changed a good bit in the Slicer nightly. I would suggest reading the markups section of the migration guide which details some changes about markup events. https://www.slicer.org/wiki/Documentation/Nightly/Developers/Tutorials/MigrationGuide/Slicer#Markups

Another discussion about recent changes to Markups events can be found at:
Handle Markups events from an external module

Very informative links. Thanks!

I’ve updated the markups observation examples in the script repository according to the changed API.

1 Like