# SliceViews - Propagate volume selection is not working?

**URL:** <https://discourse.slicer.org/t/sliceviews-propagate-volume-selection-is-not-working/35494>\
**Category:** Development\
**Created:** [April 15, 2024, 1:37pm UTC](https://discourse.slicer.org/t/sliceviews-propagate-volume-selection-is-not-working/35494 "2024-04-15T13:37:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Davide\_Scorza](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/davide_scorza/32/70057_2.png) [@Davide\_Scorza](https://discourse.slicer.org/u/Davide_Scorza)\
**Post date:** [April 15, 2024, 1:37pm UTC](https://discourse.slicer.org/t/sliceviews-propagate-volume-selection-is-not-working/35494/1 "2024-04-15T13:37:23Z")

</div>

Dear slicer community,

I’ve been used Slicer from quite a while, and I am currently writing a new module which uses some “old” functions I wrote time ago to automate some interaction with 3D Slicer.

In particular, I need to set the sliceViews to a specific volume I just pushed into 3D slicer. To do so, I used the following functions:

```auto
def get_slice_view(color_string):
    lm = slicer.app.layoutManager()
    selected_slice = lm.sliceWidget(color_string)
    return selected_slice

```

and

```auto
def set_volume_to_slice_view(
    volume_node, slice_node, layer="background", propagate=False
):
    """
    Assign a volumeNode to a specific view.

    :param volume_node: volume to assign to a specific view
    :param slice_node: select the slice_node. Could be either the slice_node or the string
                        ['Red', 'Yellow', 'Green']
    :param layer: string specifying the layer where to put the volumeNode
                ['background', 'foreground', 'labelmap']
    :param layer:
    :param propagate:

    :return: True (success) or False (Failure)
    """
    if isinstance(slice_node, str):
        slice_node = get_slice_view(slice_node)

    try:
        logic = slice_node.sliceLogic()
        composite_node = logic.GetSliceCompositeNode()
    except AttributeError:
        slice_node = get_slice_view(slice_node.GetName())
        logic = slice_node.sliceLogic()
        composite_node = logic.GetSliceCompositeNode()

    if layer == "background":
        composite_node.SetBackgroundVolumeID(volume_node.GetID())
        if propagate:
            slicer.app.applicationLogic().PropagateBackgroundVolumeSelection(0)
        return True
    elif layer == "foreground":
        composite_node.SetForegroundVolumeID(volume_node.GetID())
        if propagate:
            slicer.app.applicationLogic().PropagateForegroundVolumeSelection(0)
        return True
    elif layer == "labelmap":
        composite_node.SetLabelVolumeID(volume_node.GetID())
        if propagate:
            slicer.app.applicationLogic().PropagateLabelVolumeSelection(0)
        return True
    else:
        logging.info(" ***Error assigning volume to slice View***")
        return False

```

I tested this same code, and it is working without the Propagate\*VolumeSelection() (meaning the propagate flag in my function set to True).

I am wondering if I am using it wrong, it is just my problem or it is a function bug.  
As I said, with propagate=False the function is working (however, only a single sliceView is changing), and I replicate the failure directly in the 3D Slicer python interactor.

I am using Slicer 5.2.2, on Windows platform.

Thanks in advance for any help you could provide.  
Great job with the platform by the way!  
Best Regards,  
Davide

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [April 15, 2024, 6:33pm UTC](https://discourse.slicer.org/t/sliceviews-propagate-volume-selection-is-not-working/35494/2 "2024-04-15T18:33:11Z")

</div>

You might want to try:

> <https://github.com/Slicer/Slicer/blob/main/Base/Python/slicer/util.py#L527>

---

<div class="post-metadata">

**Author:** ![Davide\_Scorza](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/davide_scorza/32/70057_2.png) [@Davide\_Scorza](https://discourse.slicer.org/u/Davide_Scorza)\
**Post date:** [April 16, 2024, 7:08am UTC](https://discourse.slicer.org/t/sliceviews-propagate-volume-selection-is-not-working/35494/3 "2024-04-16T07:08:23Z")

</div>

Thank you very much @pieper, it did exactly what I needed.  
I did look into the utils module from the embedded interpreter, and missed that one.

Thanks again.  
Davide
