Pre-selecting Foreground and Background Volumes

I want to pre-select the background and foreground volumes manually. Like seen below, right now there are no volumes selected for the background and foreground layer.


I have tried the following methods but even after updating the view, the combo box value itself is not changed.

lm =
sliceWidget = lm.sliceWidget(‘Red’)
ForeCombo = findChild(sliceWidget, ‘ForegroundComboBox’)

I have also tried directly modifying the slice widget like so:

red_logic =“Red”).sliceLogic()
red_cn = red_logic.GetSliceCompositeNode()

Any help would be appreciated!

This works for me:

import SampleData
h = SampleData.SampleDataLogic().downloadMRHead()
c = SampleData.SampleDataLogic().downloadCTACardio()
red_logic ='Red').sliceLogic()
red_cn = red_logic.GetSliceCompositeNode()

And afterwards you should have this:


As Steve mentioned. More examples at

I think the easiest way to set which volumes to show in slice views is by using slicer.util.setSliceViewerLayers:

1 Like