# SetItemDisplayVisibility works only occasionally

**URL:** https://discourse.slicer.org/t/setitemdisplayvisibility-works-only-occasionally/31250
**Category:** Development
**Tags:** python
**Created:** [August 20, 2023, 2:14pm UTC](https://discourse.slicer.org/t/setitemdisplayvisibility-works-only-occasionally/31250 "2023-08-20T14:14:10Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![moraleda](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/moraleda/32/77356_2.png) [@moraleda](https://discourse.slicer.org/u/moraleda)
#### Post date: [August 20, 2023, 2:14pm UTC](https://discourse.slicer.org/t/setitemdisplayvisibility-works-only-occasionally/31250/1 "2023-08-20T14:14:10Z")

</div>

Hi there,

I am creating multiple lineNodes and storing them in multiple folders with Python console in Slicer. E.g. I have folder1 with line1-1, line2-2 and folder2 with line2-1, line2-2. After creating, I want to set visibility to 0 and deexpand the folders. But the following code works only for deexpanding the folders and it just ignores the first line.

```auto
for folderID in folderIDsList:
    shNode.SetItemDisplayVisibility(folderID,0)
    shNode.SetItemExpanded(folderID, 0)

```

Lets say ‘folderIDsList = [30,42]’. If I then run single line command ‘shNode.SetItemDisplayVisibility(42,0)’ it also does not do anything.  
But if I click with my mouse on the Eye by the folder in the module panel and run the for-loop again, it works!

Could you please explain this behavior to me?

Thank a lot!

Ps.: ‘shNode = slicer.mrmlScene.GetSubjectHierarchyNode()’

---

<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: [August 20, 2023, 2:17pm UTC](https://discourse.slicer.org/t/setitemdisplayvisibility-works-only-occasionally/31250/2 "2023-08-20T14:17:43Z")

</div>

Display nodes are created when needed, for example when you click on the eye icon of a folder item. You can also create a folder display node and set it in the folder item using Python scripting.

---

<div class="post-metadata">

### Author: ![moraleda](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/moraleda/32/77356_2.png) [@moraleda](https://discourse.slicer.org/u/moraleda)
#### Post date: [August 21, 2023, 8:38am UTC](https://discourse.slicer.org/t/setitemdisplayvisibility-works-only-occasionally/31250/3 "2023-08-21T08:38:18Z")

</div>

Thank you for the explanation!

I then found more out here: [Script repository — 3D Slicer documentation](https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#manipulate-subject-hierarchy-item)

(Maybe it is useful for future readers.)
