Python console warnings for deprecated methods

I was debugging a code that iterated over segmentation nodes as below

sn = slicer.mrmlScene.GetFirstNodeByClass('vtkMRMLSegmentationNode')
while sn:
  ...
  sn = slicer.mrmlScene.GetNextNodeByClass('vtkMRMLSegmentationNode')

and it was getting only the first node from the scene.

I then searched for the method in the source code, and found that the method I was using was deprecated: https://github.com/Slicer/Slicer/blob/master/Libs/MRML/Core/vtkMRMLScene.h#L246-L253

There is even a vtkWarningMacro() in the implementation of that method: https://github.com/Slicer/Slicer/blob/master/Libs/MRML/Core/vtkMRMLScene.cxx#L1655, but nothing gets printed out on the console to warn the user when that method is used (at least not for me).

Is that warning supposed to be printed? Is it a bug, or some setting that prevented me from seeing it?

You can use getNodesByClass method to get all nodes of a certain class in a Python list.

slicer.mrmlScene.GetNextNodeByClass() failed for you because traversing the MRML node list is initialized by slicer.mrmlScene.InitTraversal() method call (and not GetFirstNodeByClass). We kept the method for only backward compatibility. Documentation of how to use it was removed because it could have encouraged people to use it.

VTK errors are not printed on the Python console. It is not a bug, but I agree that it could be a useful feature to have. We would probably not want to flood the console with log VTK messages all the time, so I’m not sure what the expected behavior would be.

Thanks Andras. I was able to quickly fix the code once I realized that method was deprecated.