Error Trying to Set Background Volume to a Slice Node in Slicelet

Operating system: MacOS 10.13.4
Slicer version: 4.9.0 nightly 2018-8-10
Expected behavior: Ability to set a composite node of a sliceNode to a particular background volume
Actual behavior: ‘NoneType’ object has no attribute ‘GetSliceCompositeNode’

Hi all,

I’m trying to set a SliceNode to a particular background volume within a Slicelet when a button is clicked. Everything works well when button is clicked (volumes load, sliceNode default views are all set to ‘Axial’) except being able to set a SliceNode to a particular background volume. Is it possible that slicer.app.applicationLogic() isnt loading properly?

Vol_list is a list of volume nodes.

sliceNodes = slicer.util.getNodesByClass('vtkMRMLSliceNode')		
for i,sliceNode in enumerate(sliceNodes):
				sliceNode.SetOrientation("Axial")
for i,sliceNode in enumerate(sliceNodes):
				  applicationLogic = slicer.app.applicationLogic()
				  sliceLogic = applicationLogic.GetSliceLogic(sliceNode)
				  sliceLogic.GetSliceCompositeNode().SetBackgroundVolumeID(vol_list[i].GetID())

'NoneType' object has no attribute 'GetSliceCompositeNode'

Thanks for any advice or thoughts!

Best,

Brett

You can find example code for this and many similar tasks in the script repository.

Hi Andras, these are the examples I’ve already been using as a guide… is the code I’ve written above incorrect?

Please have a look at the current example in the script repository that uses slicer.util.setSliceViewerLayers.

The error indicates that no slice logic is found for a particular slice node. Maybe you are trying to access a slice node that is not used in any view. It is safer to iterate through slice nodes that are used in the current layout as it is done in this example. This might also happen if you have created new slice nodes immediately before and associated slice logics are not ready yet (to solve this, you can call your method via a singleshot timer to make sure all scene updates are completed before your code runs).

Andras, thanks for the suggestions!

I could be wrong but seemed to run into issues whenever I called slicer.app.layoutManager() or slicer.app.applicationLogic(). They always turn up empty. But when I called these methods within the Python interacter in Slicer they would work fine. I didn’t investigate further using a singleshot timer… maybe that would have helped.

The alternate approach looping through nodes as you mentioned did the trick. Neglected to mention that the aim was to load a different unique image for each viewer which is a familiar layout for radiologists reading MR studies.

vol_list = [list of different volumes already loaded into slicer]
viewNodes = slicer.mrmlScene.GetNodesByClass('vtkMRMLSliceCompositeNode')
for i,viewNode in enumerate(viewNodes):
	viewNode.SetBackgroundVolumeID(vol_list[i].GetID())

Thanks again for your assistance.

-Brett

How do you start Slicer?

/Applications/Slicer.app/Contents/MacOS/Slicer --no-main-window --python-script seg_widget.py --raw ./RSTestData/Raw/ --ann ./RSTestData/Annotations --assignment ./RSTestData/assignment

This means there is no main window. No layout manager. No slice views.

1 Like