Can't hide rulers from specific 3d Views (with python)

I’m having trouble displaying an Annotation Ruler in only certain 3D views.

For example, when using the Dual 3D Layout, I quickly create both a Fiducial and Ruler. If I input the following up the python interactor, the Fiducial disappears from the second 3D view (as expected):

getNode('vtkMRMLMarkupsFiducialNode1').GetDisplayNode().AddViewNodeID('vtkMRMLViewNode1')

However, if I input the following for the AnnotationRulerNode, the ruler does not disappear from the second 3D View:

getNode('vtkMRMLAnnotationRulerNode1').GetDisplayNode().AddViewNodeID('vtkMRMLViewNode1')

The ruler node actually has 3 display nodes, so I tried it on all 3, but it still did not work:

getNode('vtkMRMLAnnotationRulerNode1').GetNthDisplayNode(0).AddViewNodeID('vtkMRMLViewNode1')
getNode('vtkMRMLAnnotationRulerNode1').GetNthDisplayNode(1).AddViewNodeID('vtkMRMLViewNode1')
getNode('vtkMRMLAnnotationRulerNode1').GetNthDisplayNode(2).AddViewNodeID('vtkMRMLViewNode1')

And finally, the ruler automatically appears under a hierarchy, so I also tried the following, but again without success:

getNode('vtkMRMLAnnotationHierarchyNode2').GetDisplayNode().AddViewNodeID('vtkMRMLViewNode1')
getNode('vtkMRMLAnnotationHierarchyNode1').GetDisplayNode().AddViewNodeID('vtkMRMLViewNode1')

I also removed the ruler from the hierarchy, and tried all of the above, but it did not work. Is there something I am missing, or is this a bug in Slicer?

Thanks,
Brian

You may try calling RemoveAllViewNodeIDs before adding node IDs.

Annotation rulers are being phased out. In recent Slicer Preview Releases you can use Markups lines instead.

Hi Brian,

I encountered the same case not long before. I did a silly way to go through all rulers and check their names to let decide show or hide:

  value = 0 # hide
  value = 1 # show
  for i in range(NumofRulers):
        nodeName = 'Line-Ruler_No'+str(i+1)  # ruler Node's name
        node = slicer.util.getNode(nodeName)
        if node:
             node.SetDisplayVisibility(value)

Hope it helps.

Thanks. I ended up using Markup Lines, and everything works as expected

1 Like