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

**URL:** <https://discourse.slicer.org/t/error-trying-to-set-background-volume-to-a-slice-node-in-slicelet/4638>\
**Category:** Support\
**Tags:** slicelet\
**Created:** [November 5, 2018, 3:10pm UTC](https://discourse.slicer.org/t/error-trying-to-set-background-volume-to-a-slice-node-in-slicelet/4638 "2018-11-05T15:10:20Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![bsmarine](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/bsmarine/32/3898_2.png) [@bsmarine](https://discourse.slicer.org/u/bsmarine)\
**Post date:** [November 5, 2018, 3:10pm UTC](https://discourse.slicer.org/t/error-trying-to-set-background-volume-to-a-slice-node-in-slicelet/4638/1 "2018-11-05T15:10:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [November 5, 2018, 4:41pm UTC](https://discourse.slicer.org/t/error-trying-to-set-background-volume-to-a-slice-node-in-slicelet/4638/2 "2018-11-05T16:41:48Z")

</div>

You can find example code for this and many similar tasks in the [script repository](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Iterate_over_current_visible_slice_views.2C_and_set_foreground_and_background_images).

---

<div class="post-metadata">

**Author:** ![bsmarine](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/bsmarine/32/3898_2.png) [@bsmarine](https://discourse.slicer.org/u/bsmarine)\
**Post date:** [November 5, 2018, 5:02pm UTC](https://discourse.slicer.org/t/error-trying-to-set-background-volume-to-a-slice-node-in-slicelet/4638/3 "2018-11-05T17:02:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [November 5, 2018, 5:18pm UTC](https://discourse.slicer.org/t/error-trying-to-set-background-volume-to-a-slice-node-in-slicelet/4638/4 "2018-11-05T17:18:39Z")

</div>

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](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Show_slice_views_in_3D_window). 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).

---

<div class="post-metadata">

**Author:** ![bsmarine](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/bsmarine/32/3898_2.png) [@bsmarine](https://discourse.slicer.org/u/bsmarine)\
**Post date:** [November 6, 2018, 1:59am UTC](https://discourse.slicer.org/t/error-trying-to-set-background-volume-to-a-slice-node-in-slicelet/4638/5 "2018-11-06T01:59:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [November 6, 2018, 2:18am UTC](https://discourse.slicer.org/t/error-trying-to-set-background-volume-to-a-slice-node-in-slicelet/4638/6 "2018-11-06T02:18:46Z")

</div>

How do you start Slicer?

---

<div class="post-metadata">

**Author:** ![bsmarine](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/bsmarine/32/3898_2.png) [@bsmarine](https://discourse.slicer.org/u/bsmarine)\
**Post date:** [November 6, 2018, 3:10am UTC](https://discourse.slicer.org/t/error-trying-to-set-background-volume-to-a-slice-node-in-slicelet/4638/7 "2018-11-06T03:10:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [November 6, 2018, 3:12am UTC](https://discourse.slicer.org/t/error-trying-to-set-background-volume-to-a-slice-node-in-slicelet/4638/8 "2018-11-06T03:12:18Z")

</div>

> [@bsmarine](#):
>
> –no-main-window

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