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")
  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.AddObserver(vtk.vtkCommand.ModifiedEvent, onMarkupsNodeModified)

I see that the wiki ScriptRepository might have some outdated examples as you are referring to.
@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.

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