# Adjust volume rendering transfer function in Python

**URL:** https://discourse.slicer.org/t/adjust-volume-rendering-transfer-function-in-python/12069
**Category:** Development
**Tags:** volume-rendering
**Created:** [June 17, 2020, 12:07pm UTC](https://discourse.slicer.org/t/adjust-volume-rendering-transfer-function-in-python/12069 "2020-06-17T12:07:50Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Dootsiie](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/dootsiie/32/6299_2.png) [@Dootsiie](https://discourse.slicer.org/u/Dootsiie)
#### Post date: [June 17, 2020, 12:07pm UTC](https://discourse.slicer.org/t/adjust-volume-rendering-transfer-function-in-python/12069/1 "2020-06-17T12:07:50Z")

</div>

Hi,

I tried adjusting the transfer function on a 3D volume by using the lines of code you mentioned here. However, I do not see any difference in the 3D volume. Can you help me out? What I did, is I loaded the volume, visualized it like you did in the example above, and used the following code:

> volRenWidget = slicer.modules.volumerendering.widgetRepresentation()  
> if volRenWidget is None:  
> logging.error(‘Failed to access volume rendering module’)  
> return  
> # Make sure the proper volume property node is set  
> volumePropertyNode = displayNode.GetVolumePropertyNode()  
> if volumePropertyNode is None:  
> logging.error(‘Failed to access volume properties’)  
> return  
> volumePropertyNodeWidget = slicer.util.findChild(volRenWidget, ‘VolumePropertyNodeWidget’)  
> volumePropertyNodeWidget.setMRMLVolumePropertyNode(volumePropertyNode)  
> # Adjust the transfer function  
> volumePropertyNodeWidget.moveAllPoints(x, 0, false)

---

<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: [June 17, 2020, 12:27pm UTC](https://discourse.slicer.org/t/adjust-volume-rendering-transfer-function-in-python/12069/2 "2020-06-17T12:27:21Z")

</div>

This function works for me, please see it as example:

> <https://gist.github.com/cpinter/8a1f71c7eb3ef0ebcaa6c1be6e1c9d4a>

For the record, this is the topic referred to above:

> [@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…
