slicer.util.MRMLNodeNotFoundException: could not find nodes in the scene by name or id '' error

Operating system: windows 10
Slicer version: 4.11.20200930
Expected behavior: run a scripted python module without errors

Hello. I’m using a scripted python module on 3D slicer version 4.4 and it works as it should.
However, when I use the same module in the 3D slicer version 4.11.20200930 it has different behavior and I’m getting this error message:

slicer.util.MRMLNodeNotFoundException: could not find nodes in the scene by name or id ‘’.
Are there any changes in getting the imported data?

I would really appreciate your help.

Thanks,
Mariana

getNode is a helper function that used to return None when there were no matches, but in more recent Slicer it raises that exception to be explicit. Now you need to add a catch it, something like this.

Thank you very much. It works!

You can also use slicer.mrmlScene.GetNodeByID() as a drop-in replacement (if node is not found then it returns None instead of throwing an exception). Key differences between the two methods are described here.

1 Like