# \[Volume Rendering\] Works via python console but not via extension code

**URL:** https://discourse.slicer.org/t/volume-rendering-works-via-python-console-but-not-via-extension-code/23248
**Category:** Development
**Tags:** python
**Created:** [May 2, 2022, 9:05pm UTC](https://discourse.slicer.org/t/volume-rendering-works-via-python-console-but-not-via-extension-code/23248 "2022-05-02T21:05:11Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![strider\_hunter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/strider_hunter/32/8253_2.png) [@strider\_hunter](https://discourse.slicer.org/u/strider_hunter)
#### Post date: [May 2, 2022, 9:05pm UTC](https://discourse.slicer.org/t/volume-rendering-works-via-python-console-but-not-via-extension-code/23248/1 "2022-05-02T21:05:11Z")

</div>

Hi,  
When I use the following code in my Slicer Extension (Slicer 4.11.20210226), I am unable to get a volume render in the 3D view (a custom vtkMRMLViewNode).

```auto
node = slicer.util.getNode('<nodename>') # a vtkMRMLScalarVolumeNode
volRenLogic = slicer.modules.volumerendering.logic()
displayNode = volRenLogic.CreateDefaultVolumeRenderingNodes(node)
displayNode.SetVisibility(True)

```

But when I copy paste the same to the python console, it works! Upon checking the volume rendering module, I noticed that my extension code does not set the eye icon to visible, but copy-pasting the code in the python console does that. In my extension, I also use the following displayNode functions to verify if the visibility was set properly and their output is all 1.

`print (' ------ [myUtil.set3DBackground()]: ', displayNode.GetVisibility(), displayNode.GetVisibility2D(), displayNode.GetVisibility3D())`

What may I be missing here?

* * *

Note: Prior to the volume rendering, my extension updates the 3D array that makes up the `vtkMRMLScalarVolumeNode` being rendered.

---

<div class="post-metadata">

### Author: ![mau\_igna\_06](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mau_igna_06/32/9056_2.png) [@mau\_igna\_06](https://discourse.slicer.org/u/mau_igna_06)
#### Post date: [May 2, 2022, 11:58pm UTC](https://discourse.slicer.org/t/volume-rendering-works-via-python-console-but-not-via-extension-code/23248/2 "2022-05-02T23:58:51Z")

</div>

May be use a timer callback to set up the volume rendering because you need to give some time to the scalar volume to update I think

---

<div class="post-metadata">

### Author: ![strider\_hunter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/strider_hunter/32/8253_2.png) [@strider\_hunter](https://discourse.slicer.org/u/strider_hunter)
#### Post date: [May 4, 2022, 7:58am UTC](https://discourse.slicer.org/t/volume-rendering-works-via-python-console-but-not-via-extension-code/23248/3 "2022-05-04T07:58:42Z")

</div>

Thanks! It worked with the timer!

```auto
def set3DBackgroundTimed(node):
    displayNode = volRenLogic.CreateDefaultVolumeRenderingNodes(node)
    displayNode.SetVisibility(True)

qt.QTimer.singleShot(1000, lambda: set3DBackgroundTimed(node))

```
