# Set to outline mode when a segmentation node is added, NOT WORKING

**URL:** <https://discourse.slicer.org/t/set-to-outline-mode-when-a-segmentation-node-is-added-not-working/36203>\
**Category:** Development\
**Created:** [May 16, 2024, 8:35am UTC](https://discourse.slicer.org/t/set-to-outline-mode-when-a-segmentation-node-is-added-not-working/36203 "2024-05-16T08:35:56Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrlongzhang](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mrlongzhang/32/15286_2.png) [@mrlongzhang](https://discourse.slicer.org/u/mrlongzhang)\
**Post date:** [May 16, 2024, 8:35am UTC](https://discourse.slicer.org/t/set-to-outline-mode-when-a-segmentation-node-is-added-not-working/36203/1 "2024-05-16T08:35:56Z")

</div>

I used the follow code in .slicerrc.py to modify the default behavior of slicer 2D slice (up to 5.6.x) to display in outline mode instead of in filled mode for a segmentation.

```auto
def SetOutline(caller,event):
  for node in slicer.util.getNodes("*").values():
    if node.IsA("vtkMRMLSetmentationDisplayNode"):
      node.SetAllSegmentsVisibility2DOutline(1)
      node.SetAllSegmentsVisibility2DFill(0)

slicer.mrmlScene.AddObserver(slicer.mrmlScene.NodeAddedEvent, SetOutline)

```

However, I noticed that it always failed to switch to outline mode when drag-n-drop a segmentation file into the client area after a scalar volume file. However, it may switch to outline mode if I first drop a segmentation and then a volume file.

What is the root cause of such behavior? And what is the solution to this issue? A workaround is also highly appreciated!

Thx in advance!

---

<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:** [May 16, 2024, 8:39am UTC](https://discourse.slicer.org/t/set-to-outline-mode-when-a-segmentation-node-is-added-not-working/36203/2 "2024-05-16T08:39:07Z")

</div>

> [@mrlongzhang](#):
>
> vtkMRMLSetmentationDisplayNode

First of all, there is a typo in this, ‘t’ =\> ‘g’

---

<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:** [May 16, 2024, 12:37pm UTC](https://discourse.slicer.org/t/set-to-outline-mode-when-a-segmentation-node-is-added-not-working/36203/3 "2024-05-16T12:37:42Z")

</div>

I would recommend to change this in the default segmentation display node. You can find examples in the script repository how to change default nodes in the scene.

---

<div class="post-metadata">

**Author:** ![mrlongzhang](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mrlongzhang/32/15286_2.png) [@mrlongzhang](https://discourse.slicer.org/u/mrlongzhang)\
**Post date:** [May 17, 2024, 2:50am UTC](https://discourse.slicer.org/t/set-to-outline-mode-when-a-segmentation-node-is-added-not-working/36203/4 "2024-05-17T02:50:06Z")

</div>

The code posted here was wrong. But this is not the root cause as I mentioned in the text, it works when you first drop a seg instead of a vol.

---

<div class="post-metadata">

**Author:** ![mrlongzhang](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mrlongzhang/32/15286_2.png) [@mrlongzhang](https://discourse.slicer.org/u/mrlongzhang)\
**Post date:** [May 17, 2024, 2:59am UTC](https://discourse.slicer.org/t/set-to-outline-mode-when-a-segmentation-node-is-added-not-working/36203/6 "2024-05-17T02:59:38Z")

</div>

this is not working. in 4.13, there is no any hints. however, in 5.6, it nicely gives a hint: [VTK] vtkMRMLSegmentationDisplayNode::GetSegmentIDs: No segmentation node is associated to this display node

it looks like that segmentation display node has dependency issues on data: it can not be correctly constructed/configured w/o a segmentation node.

---

<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:** [May 17, 2024, 9:00am UTC](https://discourse.slicer.org/t/set-to-outline-mode-when-a-segmentation-node-is-added-not-working/36203/7 "2024-05-17T09:00:39Z")

</div>

> [@mrlongzhang](#):
>
> display node has dependency issues on data: it can not be correctly constructed/configured w/o a segmentation node

Correct. A display node controls the display properties of a data node, so without a data node it has no reason to exist. Usually you can make sure a display node exists after creating/accessing the data node by calling `CreateDefaultDisplayNodes()` on the data node, and then you can get it by calling `GetDisplayNode()`.
