How to assign default color table to a node

I wonder if this is too trivial for appearing here but I struggle for weeks before realizing that you can easily assign a color table to a node in python

# First access the color table by name, the name is the one that appears in the combobox
PETnodeColor = slicer.util.getFirstNodeByName('PET-Heat')
# Now you get your node display, the node is any vtkMRMLScalarVolumeNode that you have already loaded
displaynode = node.GetScalarVolumeDisplayNode()
# Finally the assignment
displaynode.SetAndObserveColorNodeID(PETnodeColor.GetID())

This does not even appear in the documentation nor the wiki and is really hard to find

3 Likes

There was an example for setting colormap of a volume in the Slicer script repository. This page has a lot of examples for python scripting.

It was in an example titled “Change window/level (brightness/contrast) or colormap of a volume”.
https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Change_window.2Flevel_.28brightness.2Fcontrast.29_or_colormap_of_a_volume

2 Likes