# How to use Python to achieve the thresholding effect of the ‘Volumes’ module? (synchronized with the volume rendering)

**URL:** https://discourse.slicer.org/t/how-to-use-python-to-achieve-the-thresholding-effect-of-the-volumes-module-synchronized-with-the-volume-rendering/20891
**Category:** Support
**Tags:** threshold, python, volume-rendering
**Created:** [December 2, 2021, 10:13pm UTC](https://discourse.slicer.org/t/how-to-use-python-to-achieve-the-thresholding-effect-of-the-volumes-module-synchronized-with-the-volume-rendering/20891 "2021-12-02T22:13:31Z")
**Posts on this page:** 3
**Page:** 3

<div class="post-metadata">

### Author: ![dalv.silvermann](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/dalv.silvermann/32/16193_2.png) [@dalv.silvermann](https://discourse.slicer.org/u/dalv.silvermann)
#### Post date: [August 2, 2022, 9:56am UTC](https://discourse.slicer.org/t/how-to-use-python-to-achieve-the-thresholding-effect-of-the-volumes-module-synchronized-with-the-volume-rendering/20891/43 "2022-08-02T09:56:16Z")

</div>

Hi to all Discoursers here! I’v got a lot knowledge from this resource. Thank you very much ya all!

Plese, help me to find:

1. How I can set the checkbox called “Synchronize with volumes module” in module called “Volume Rendering” from python code? How I can set it for a chosen volume (set only for special volume name with slicer.mrmlScene.GetFirstNodeByName())
2. How I can set it by default always “On” at start of the Slicer?

Thank ya all!

---

<div class="post-metadata">

### Author: ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)
#### Post date: [August 2, 2022, 3:07pm UTC](https://discourse.slicer.org/t/how-to-use-python-to-achieve-the-thresholding-effect-of-the-volumes-module-synchronized-with-the-volume-rendering/20891/44 "2022-08-02T15:07:36Z")

</div>

The steps described here should work for you:

[https://slicer.readthedocs.io/en/latest/developer\_guide/python\_faq.html#how-to-find-a-python-function-for-any-slicer-features](https://slicer.readthedocs.io/en/latest/developer_guide/python_faq.html#how-to-find-a-python-function-for-any-slicer-features)

---

<div class="post-metadata">

### Author: ![dalv.silvermann](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/dalv.silvermann/32/16193_2.png) [@dalv.silvermann](https://discourse.slicer.org/u/dalv.silvermann)
#### Post date: [August 2, 2022, 9:35pm UTC](https://discourse.slicer.org/t/how-to-use-python-to-achieve-the-thresholding-effect-of-the-volumes-module-synchronized-with-the-volume-rendering/20891/45 "2022-08-02T21:35:34Z")

</div>

Thank you very much! Your advice helped me to find the way, it was definitely what I need to know in regard to all GUI elements in the Slicer. This code is work for me:

```auto
volumeRenderingWidgetRep.setMRMLVolumeNode(slicer.mrmlScene.GetNodeByID('vtkMRMLScalarVolumeNode11'))
volumeRenderingWidgetRep = slicer.modules.volumerendering.widgetRepresentation()
volumeRenderingWidgetRep.mrmlDisplayNode().GetFollowVolumeDisplayNode()
followGet = volumeRenderingWidgetRep.mrmlDisplayNode().GetFollowVolumeDisplayNode()
followSet = volumeRenderingWidgetRep.mrmlDisplayNode().SetFollowVolumeDisplayNode(1)
volumeName = "635166: AXIAL cropped_9"
volNode = getNode(volumeName)
dispNode = volNode.GetDisplayNode()
lowerThreshValue = 267
upperThreshValue = 32767
dispNode.SetThreshold(lowerThreshValue, upperThreshValue)
volNode.GetDisplayNode().ApplyThresholdOn()

```

Need to note, that `'vtkMRMLScalarVolumeNode11'` and `"635166: AXIAL cropped_9"` is the same node :0)

[Previous page](https://discourse.slicer.org/t/how-to-use-python-to-achieve-the-thresholding-effect-of-the-volumes-module-synchronized-with-the-volume-rendering/20891.md?page=2)
