Volume Rendering with Python

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.

#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()

volRenLogic.UpdateDisplayNodeFromVolumeNode(displayNode, volumeNode, presetNode)

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.