# How to select a volume automatically in volume rendering?

**URL:** <https://discourse.slicer.org/t/how-to-select-a-volume-automatically-in-volume-rendering/30989>\
**Category:** Support\
**Created:** [August 5, 2023, 2:47am UTC](https://discourse.slicer.org/t/how-to-select-a-volume-automatically-in-volume-rendering/30989 "2023-08-05T02:47:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![telomere](https://avatars.discourse-cdn.com/v4/letter/t/e47c2d/32.png) [@telomere](https://discourse.slicer.org/u/telomere)\
**Post date:** [August 5, 2023, 2:47am UTC](https://discourse.slicer.org/t/how-to-select-a-volume-automatically-in-volume-rendering/30989/1 "2023-08-05T02:47:11Z")

</div>

Hi, I’m making some script to make my work faster.

I made a simple shortcut button that just goes to volume rendering.

When it changes to volume rendering module, no volume is selected as a default(even when some volumes are loaded in data)

![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/b/f/bfde6453a14ae2ed86cb110da6af46f2649b6085.png)

I want to make a code that switches to volume rendering and select volumes that I want(like first-loaded volume, second-loaded volume…etc).  
Making a button for switching was simple but selecting some volume as a default is not solved…

Any help appreciating. Thanks.

---

<div class="post-metadata">

**Author:** ![muratmaga](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muratmaga/32/3622_2.png) [@muratmaga](https://discourse.slicer.org/u/muratmaga)\
**Post date:** [August 5, 2023, 3:25pm UTC](https://discourse.slicer.org/t/how-to-select-a-volume-automatically-in-volume-rendering/30989/2 "2023-08-05T15:25:43Z")

</div>

You can probably write a little function that will cycle over the loaded volumes in the scene after a keystroke. In each iteration you can turn off the previous volume and turn on the next one,

Otherwise I am not sure how can rendering will know what volume you want to render automatically.

---

<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:** [August 6, 2023, 11:11pm UTC](https://discourse.slicer.org/t/how-to-select-a-volume-automatically-in-volume-rendering/30989/3 "2023-08-06T23:11:23Z")

</div>

After you switched to a module, you can use `setEditedNode` to select what node the module should display.

For example:

```python
myModuleWidget = slicer.modules.mymodule.widgetRepresentation()
myVolume = slicer.util.getNode('myVolume')
myModuleWidget.setEditedNode(myVolume)

```

---

<div class="post-metadata">

**Author:** ![telomere](https://avatars.discourse-cdn.com/v4/letter/t/e47c2d/32.png) [@telomere](https://discourse.slicer.org/u/telomere)\
**Post date:** [August 7, 2023, 12:11am UTC](https://discourse.slicer.org/t/how-to-select-a-volume-automatically-in-volume-rendering/30989/4 "2023-08-07T00:11:04Z")

</div>

Thanks!  
I solved my problem with the code below:

```python
volumeNodes = slicer.mrmlScene.GetNodesByClass('vtkMRMLScalarVolumeNode')
secondVolumeNode = volumeNodes.GetItemAsObject(1)
vrWidget = slicer.modules.volumerendering.widgetRepresentation()
vrWidget.setMRMLVolumeNode(secondVolumeNode)

```

With this, second loaded volume is selected in Volume Rendering combobox if I want to load second-loaded volume among several loaded volume.

Please help one more!(Maybe not one…but…)  
I made a shortcut to go Segment Editor module and automatically load source volume and add segmentation and segment.  
In this situation, I also want to control “specify geometry” button which is next to source volume.  
I want to choose ROI that I made previously and set spacing as 0.15mm.  
But I never could find the function codes for controlling ‘specify geometry’ ☹

---

<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:** [August 7, 2023, 8:09am UTC](https://discourse.slicer.org/t/how-to-select-a-volume-automatically-in-volume-rendering/30989/5 "2023-08-07T08:09:43Z")

</div>

Thresholding for sharing the solution that worked for you. I would recommend to use `myModuleWidget.setEditedNode(myVolume)` method, as that is a higher-level API that works all modules.

Please create a new topic for new questions that are unrelated to this topic.
