# Is there a way to getCurrentVolumeNode?

**URL:** <https://discourse.slicer.org/t/is-there-a-way-to-getcurrentvolumenode/15060>\
**Category:** Support\
**Created:** [December 14, 2020, 9:10pm UTC](https://discourse.slicer.org/t/is-there-a-way-to-getcurrentvolumenode/15060 "2020-12-14T21:10:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Justin](https://avatars.discourse-cdn.com/v4/letter/j/3ab097/32.png) [@Justin](https://discourse.slicer.org/u/Justin)\
**Post date:** [December 14, 2020, 9:10pm UTC](https://discourse.slicer.org/t/is-there-a-way-to-getcurrentvolumenode/15060/1 "2020-12-14T21:10:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [December 14, 2020, 9:22pm UTC](https://discourse.slicer.org/t/is-there-a-way-to-getcurrentvolumenode/15060/2 "2020-12-14T21:22:57Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Justin](https://avatars.discourse-cdn.com/v4/letter/j/3ab097/32.png) [@Justin](https://discourse.slicer.org/u/Justin)\
**Post date:** [December 15, 2020, 10:36am UTC](https://discourse.slicer.org/t/is-there-a-way-to-getcurrentvolumenode/15060/3 "2020-12-15T10:36:18Z")

</div>

> [@lassoan](#):
>
> slicer.mrmlScene.GetFirstNodeByClass(‘vtkMRMLScalarVolumeNode’)

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