# Segment Visibility Code Not Functioning for me

**URL:** <https://discourse.slicer.org/t/segment-visibility-code-not-functioning-for-me/5974>\
**Category:** Development\
**Tags:** segmentation\
**Created:** [February 28, 2019, 10:03pm UTC](https://discourse.slicer.org/t/segment-visibility-code-not-functioning-for-me/5974 "2019-02-28T22:03:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![coolsocks](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/coolsocks/32/3299_2.png) [@coolsocks](https://discourse.slicer.org/u/coolsocks)\
**Post date:** [February 28, 2019, 10:03pm UTC](https://discourse.slicer.org/t/segment-visibility-code-not-functioning-for-me/5974/1 "2019-02-28T22:03:48Z")

</div>

Hi,  
I have an issue where indeed I can set the entire segmentation to not be visible via vtkMRMLSegmentationNode by doing:  
display = segmentation.GetDisplayNode()  
display.SetVisibility(0)

However, whenever I attempt to set a particular segment to not be visible by doing:  
display.SetSegmentVisibility(segment\_id,0)  
The segment is still visible to me. When I attempt accessing the node through Python I indeed see that the Visibility for the segment has been set to false, however why is the segment still appearing on my views?  
Am I missing some code here?  
Thanks!

---

<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:** [February 28, 2019, 10:27pm UTC](https://discourse.slicer.org/t/segment-visibility-code-not-functioning-for-me/5974/2 "2019-02-28T22:27:07Z")

</div>

Thanks for the detailed explanation!

What Slicer version do you use?  
I tried a recent nightly, and the same code works for me. Is it possible that you try to use the name of the segment and not its ID? If you rename a segment then its ID will still be the original ‘Segment\_1’ for example, and GetSegmentVisibility will return a simple False on invalid ID as well (but an error appears in the log saying “GetSegmentVisibility: No display properties found for segment with ID artery”).  
What if you do this instead?

`display.SetSegmentVisibility(segmentation.GetSegmentation().GetSegmentIdBySegmentName(segment_id), False)`

---

<div class="post-metadata">

**Author:** ![coolsocks](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/coolsocks/32/3299_2.png) [@coolsocks](https://discourse.slicer.org/u/coolsocks)\
**Post date:** [March 1, 2019, 2:35pm UTC](https://discourse.slicer.org/t/segment-visibility-code-not-functioning-for-me/5974/3 "2019-03-01T14:35:16Z")

</div>

> [@coolsocks](#):
>
> can set the entire segmentation to not be visible via vtkMRMLSegmentationNode by doing:  
> display = segmentation.GetDisplayNode()  
> display.SetVisibility(0)
> 
> However, whenever I attempt to set a particular segment to not be visible by doing:  
> display.SetSegmentVisibility(segment\_id,0)  
> The segment is still visible to me. When I attempt accessing the node through Python I indeed see that the Visibility for the segment has been set to false, however why is the segment still appearing on my views?

Thanks that did the trick! I must’ve mixed up the two.
