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

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!

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

1 Like

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:

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)

1 Like