# Get Segmentation layer

**URL:** <https://discourse.slicer.org/t/get-segmentation-layer/3312>\
**Category:** Development\
**Tags:** segmentation\
**Created:** [June 27, 2018, 9:41am UTC](https://discourse.slicer.org/t/get-segmentation-layer/3312 "2018-06-27T09:41:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fernando](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fernando/32/5640_2.png) [@Fernando](https://discourse.slicer.org/u/Fernando)\
**Post date:** [June 27, 2018, 9:41am UTC](https://discourse.slicer.org/t/get-segmentation-layer/3312/1 "2018-06-27T09:41:31Z")

</div>

Hi all,

In my `.slicerrc.py` I create a slider to visualize MIPs of different slab thicknesses on all views:

```auto
logics = getSlicesLogics()
nodes = getSlicesNodes()
for sliceNode, sliceLogic in zip(nodes, logics):
    layers = [
        sliceLogic.GetBackgroundLayer(),
        sliceLogic.GetForegroundLayer(),
        sliceLogic.GetLabelLayer(),
    ]
    for layer in layers:
        reslice = layer.GetReslice()
        reslice.SetSlabModeToMax()
        reslice.SetSlabNumberOfSlices(int(value))
        reslice.SetSlabSliceSpacingFraction(0.5)
        sliceNode.Modified()

```

How do I get access to the Segmentation layer? There is no `sliceLogic.GetSegmentationLayer()`.

---

<div class="post-metadata">

**Author:** ![ihnorton](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/ihnorton/32/9_2.png) [@ihnorton](https://discourse.slicer.org/u/ihnorton)\
**Post date:** [June 27, 2018, 12:07pm UTC](https://discourse.slicer.org/t/get-segmentation-layer/3312/2 "2018-06-27T12:07:20Z")

</div>

`.slicerrc.py` execution happens very early in the application loading process. If something is missing that you would normally find in the command prompt, it usually means that the corresponding library hasn’t been fully loaded yet. Probably the simplest option is to create a scripted module with your functionality. If you still want to use `slicerrc`, then you can hook up delayed loading with the `onStartupCompleted` event. See:

> <https://github.com/Slicer/Slicer/blob/master/Applications/SlicerApp/Testing/Python/SlicerStartupCompletedTestHelperModule.py#L19>

For example, you might put the delay loaded code in a separate file, and do something like this in `slicerrc.py`:

```auto
def load_delayed():
  execfile("/path/to/delay_load.py")

slicer.app.connect("startupCompleted()", load_delayed)

```

---

<div class="post-metadata">

**Author:** ![Fernando](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fernando/32/5640_2.png) [@Fernando](https://discourse.slicer.org/u/Fernando)\
**Post date:** [June 27, 2018, 12:50pm UTC](https://discourse.slicer.org/t/get-segmentation-layer/3312/3 "2018-06-27T12:50:06Z")

</div>

Hi @ihnorton,

Thanks for your answer. I might have not been totally clear. There isn’t anything missing on startup in my case, the slice nodes don’t have a `GetSegmentationLayer` method even in the Python console. That’s a name I made up in order to explain what I wanted to do.

@cpinter might be able to help, I think he worked on this when the Segmentations framework was included in the core.

---

<div class="post-metadata">

**Author:** ![cpinter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cpinter/32/7995_2.png) [@cpinter](https://discourse.slicer.org/u/cpinter)\
**Post date:** [June 27, 2018, 2:18pm UTC](https://discourse.slicer.org/t/get-segmentation-layer/3312/4 "2018-06-27T14:18:59Z")

</div>

Hi Fernando,  
Segmentation is a totally different animal than the other layers. As it’s not a volume, it has its own 2D displayable manager. It’s more complicated than the volume one because it can show the labelmap as well as the closed surface. In order to do the same thing for segmentations, we’d need to implement slab mode in vtkMRMLSegmentationDisplayableManager2D and add the same options to vtkMRMLSegmentationDisplayNode.

---

<div class="post-metadata">

**Author:** ![Fernando](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fernando/32/5640_2.png) [@Fernando](https://discourse.slicer.org/u/Fernando)\
**Post date:** [June 27, 2018, 2:33pm UTC](https://discourse.slicer.org/t/get-segmentation-layer/3312/5 "2018-06-27T14:33:17Z")

</div>

Ok @cpinter, thanks for the info.
