# Volume Rendering with Python

**URL:** https://discourse.slicer.org/t/volume-rendering-with-python/3431
**Category:** Support
**Created:** [July 9, 2018, 2:49pm UTC](https://discourse.slicer.org/t/volume-rendering-with-python/3431 "2018-07-09T14:49:35Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![trnhx001](https://avatars.discourse-cdn.com/v4/letter/t/ed655f/32.png) [@trnhx001](https://discourse.slicer.org/u/trnhx001)
#### Post date: [July 9, 2018, 2:49pm UTC](https://discourse.slicer.org/t/volume-rendering-with-python/3431/1 "2018-07-09T14:49:35Z")

</div>

Operating system: Windows 7  
Slicer version: 4.9.0  
Hi All,

I am trying to use python to do volume rendering and set parameters for it. These are few lines of attempt. However, I run into the problem when trying to get Volume Proper Node to set the preset “CT-Bone”. It says the volumePropertyNode is nonetype object. I wonder why this happens. Thank you for your help.

```auto
#Tune volume rendering parameters
volRenLogic = slicer.modules.volumerendering.logic()

preset = volRenLogic.GetPresetByName('CT-Bone')
presetNode = slicer.mrmlScene.AddNode(preset)
volumeNode = slicer.mrmlScene.GetNodeByID('vtkMRMLScalarVolumeNode1')
displayNode = volRenLogic.CreateVolumeRenderingDisplayNode()

volumePropertyNode = displayNode.GetVolumePropertyNode()
volumePropertyNode.Copy(preset)

volRenLogic.UpdateDisplayNodeFromVolumeNode(displayNode, volumeNode, presetNode)
slicer.mrmlScene.AddNode(displayNode)
displayNode.UnRegister(volRenLogic)
volumeNode.AddAndObserveDisplayNodeID(preset.GetID())

```

---

<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: [July 9, 2018, 6:02pm UTC](https://discourse.slicer.org/t/volume-rendering-with-python/3431/2 "2018-07-09T18:02:19Z")

</div>

CreateVolumeRenderingDisplayNode only creates display node and not volume property node. I think UpdateDisplayNodeFromVolumeNode can create and set volume property node, or you can manually create a vtkMRMLVolumePropertyNode, add to the scene, and set in the display node.

---

<div class="post-metadata">

### Author: ![cpinter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cpinter/32/7995_2.png) [@cpinter](https://discourse.slicer.org/u/cpinter)
#### Post date: [July 11, 2018, 2:48pm UTC](https://discourse.slicer.org/t/volume-rendering-with-python/3431/3 "2018-07-11T14:48:20Z")

</div>

> [@How to set volume rendering preset using Python](https://discourse.slicer.org/t/how-to-set-volume-rendering-preset-using-python/3063):
>
> Hi developers, Using a Python script I am trying to load a volume, set the slice views and also a volume rendering preset. While loading and setting the slice views works out well, the volume rendering always shows up with the default settings and not the targeted preset. Could someone please give me a hint of what’s missing? Is there a way to adjust the preset parameter “shift” in advance? Since I am new to Slicer development I would also be happy about any hint of how to improve the code (i…
