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

There is still a problem for me that when I add the marksup in a transform, and this seems naver change unless ‘harden’ the transform.
So, is there any method to find wheater a marksup was in a transform already?

If you want to get notification about transform changes, you can observe vtkMRMLTransformableNode::TransformModifiedEvent.

For performance reasons, it is important to be able to observe point coordinates changes from node transform changes, but if we find that observing two events instead of only one puts unreasonable burden on developers then we can add a new “PointModifiedWorld” event.

1 Like