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.

image

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

lm = slicer.app.layoutManager()
sliceWidget = lm.sliceWidget(‘Red’)
ForeCombo = findChild(sliceWidget, ‘ForegroundComboBox’)
ForeCombo.setCurrentNodeID(‘whole_mouse_80micron_ct’)

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

red_logic = slicer.app.layoutManager().sliceWidget(“Red”).sliceLogic()
red_cn = red_logic.GetSliceCompositeNode()
red_logic.GetSliceCompositeNode().SetBackgroundVolumeID(slicer.util.getNode(‘dwi’).GetID())

Any help would be appreciated!

This works for me:

import SampleData
h = SampleData.SampleDataLogic().downloadMRHead()
c = SampleData.SampleDataLogic().downloadCTACardio()
red_logic = slicer.app.layoutManager().sliceWidget('Red').sliceLogic()
red_cn = red_logic.GetSliceCompositeNode()
red_cn.SetBackgroundVolumeID(h.GetID())

And afterwards you should have this:

image

As Steve mentioned. More examples at

https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository

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

http://slicer.readthedocs.io/en/latest/developer_guide/slicer.html#slicer.util.setSliceViewerLayers

1 Like