Is there a way to getCurrentVolumeNode?

Dear all,
I’ve been using Slicer for a time now and am really happy with it.
However, there is one thing I have not found out.

When I’m using a script right now, I manually change the volumeNode name to a certain name.
I always only load one volumenode, never two scans at a time.

My code then uses

masterVolumeNode = getNode('name')

to get the volumeNode by name.

However, is there a way to let slicer get the currently loaded node? Independent of the name? (by selecting the only available volume node in the hierarchy?)
Something like

masterVolumeNode = getActiveNode()

In example scripts I always see examples that manually get volumeNode by name, so I wonder whether it is available at all.

Thanks a lot in advance!
Best,
Justin

If you have only a single volume loaded then you can use slicer.mrmlScene.GetFirstNodeByClass('vtkMRMLScalarVolumeNode').

If you work with multiple nodes (which is most of the time) then you add node selectors to your module GUI to let the user choose inputs and outputs.

Thanks, that’s indeed the solution to my problem!