# Adjusting "Shift" Volume Rendering Display using Python

**URL:** <https://discourse.slicer.org/t/adjusting-shift-volume-rendering-display-using-python/11731>\
**Category:** Development\
**Created:** [May 27, 2020, 1:32pm UTC](https://discourse.slicer.org/t/adjusting-shift-volume-rendering-display-using-python/11731 "2020-05-27T13:32:13Z")\
**Posts on this page:** 5\
**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:** [May 27, 2020, 1:32pm UTC](https://discourse.slicer.org/t/adjusting-shift-volume-rendering-display-using-python/11731/1 "2020-05-27T13:32:13Z")

</div>

Hi,

I am trying to visualize a volume using Python and volume rendering.  
When I render the volume, it is rather dark. I know I can solve this by moving the “Shift” bar under Display in Volume Rendering. Now I tried doing this by using Python, and I used the following code:

> volRenLogic = slicer.modules.volumerendering.logic()  
> displayNode = volRenLogic.CreateDefaultVolumeRenderingNodes(node)  
> layoutManager = slicer.app.layoutManager()  
> threeDWidget = layoutManager.threeDWidget(0)  
> threeDView = threeDWidget.threeDView()  
> threeDView.resetFocalPoint()
> 
> volRenWidget = slicer.modules.volumerendering.widgetRepresentation()  
> volumePropertyNode = displayNode.GetVolumePropertyNode()
> 
> volumePropertyNodeWidget = slicer.util.findChild(volRenWidget, ‘VolumePropertyNodeWidget’)  
> volumePropertyNodeWidget.setMRMLVolumePropertyNode(volumePropertyNode)  
> volumePropertyNodeWidget.moveAllPoints(x, 0, false)

It does visualize the volume (which is a CT scan), but when I try to apply the shift change, no visible changes are applied to the visualized volume. It does not matter what i fill in at x, but nothing seems to work, I do not get any Error messages either, it just straight up does not show the changes I made. I have tried searching these forums for a suitable answer, but i did not find anything that would completely solve this issue, and I hope anyone can help me out on this.

---

<div class="post-metadata">

**Author:** ![hemmer](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/hemmer/32/9028_2.png) [@hemmer](https://discourse.slicer.org/u/hemmer)\
**Post date:** [May 9, 2024, 12:38pm UTC](https://discourse.slicer.org/t/adjusting-shift-volume-rendering-display-using-python/11731/2 "2024-05-09T12:38:47Z")

</div>

I would also be interested to learn how to do this programmatically, and similarly, centre the volume rendering (as you would with the crosshair icon in the UI).

---

<div class="post-metadata">

**Author:** ![mikebind](https://avatars.discourse-cdn.com/v4/letter/m/71e660/32.png) [@mikebind](https://discourse.slicer.org/u/mikebind)\
**Post date:** [May 9, 2024, 3:21pm UTC](https://discourse.slicer.org/t/adjusting-shift-volume-rendering-display-using-python/11731/3 "2024-05-09T15:21:03Z")

</div>

Here is how you center the 3D view programmatically: [https://slicer.readthedocs.io/en/latest/developer\_guide/script\_repository.html#center-the-3d-view-on-the-scene](https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#center-the-3d-view-on-the-scene)

---

<div class="post-metadata">

**Author:** ![hemmer](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/hemmer/32/9028_2.png) [@hemmer](https://discourse.slicer.org/u/hemmer)\
**Post date:** [May 9, 2024, 3:27pm UTC](https://discourse.slicer.org/t/adjusting-shift-volume-rendering-display-using-python/11731/4 "2024-05-09T15:27:00Z")

</div>

Thanks Mike, that solves the centring problem!

---

<div class="post-metadata">

**Author:** ![hemmer](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/hemmer/32/9028_2.png) [@hemmer](https://discourse.slicer.org/u/hemmer)\
**Post date:** [May 9, 2025, 11:31am UTC](https://discourse.slicer.org/t/adjusting-shift-volume-rendering-display-using-python/11731/5 "2025-05-09T11:31:01Z")

</div>

And the “shift” problem can be solved following here:

> [@How to set volume rendering preset using Python](https://discourse.slicer.org/t/how-to-set-volume-rendering-preset-using-python/3063/2):
>
> Hi Oliver, There have been some improvements since 4.8.1 that makes it easier for us to do this. So if you use the latest nightly, then this is what you can do: Easier setup of volume rendering (no need to create the display node and update it from the logic): volRenLogic = slicer.modules.volumerendering.logic() displayNode = volRenLogic.CreateDefaultVolumeRenderingNodes(volumeNode) This is not very clean, because it uses widgets from the volume rendering module, but you can apply a shift li…
