# Issue hiding shapeNodes in a folder via script

**URL:** <https://discourse.slicer.org/t/issue-hiding-shapenodes-in-a-folder-via-script/44023>\
**Category:** Support\
**Created:** [August 8, 2025, 1:16pm UTC](https://discourse.slicer.org/t/issue-hiding-shapenodes-in-a-folder-via-script/44023 "2025-08-08T13:16:58Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![bserrano](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/bserrano/32/17034_2.png) [@bserrano](https://discourse.slicer.org/u/bserrano)\
**Post date:** [August 8, 2025, 1:16pm UTC](https://discourse.slicer.org/t/issue-hiding-shapenodes-in-a-folder-via-script/44023/1 "2025-08-08T13:16:59Z")

</div>

Hi all,

I’m working with a script that generates several shape nodes, grouped inside a folder.

At a certain point in the execution, I want to hide all **cylinders** in that folder. I’m using the same code that works fine with other folders, but in this particular case, the cylinders remain with `visibility=True`.

Interestingly, if I copy and paste those exact same lines into the Python interactor, they work as expected.

Has anyone experienced something similar or knows what might be causing this behavior?

I’m using Slicer 5.6.2

Thanks in advance!

```python
    # Hide cylinders ------------------------------------------------------
    slicer.app.processEvents() 
    shNode = slicer.mrmlScene.GetSubjectHierarchyNode()
    sceneItemID = shNode.GetSceneItemID()
    folderCylID = shNode.GetItemChildWithName(sceneItemID, "Cylinders_Trim")
    shNode.SetItemDisplayVisibility(folderCylID, False)

```

 ![imagen](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/2/2/226d632a86f8ebdd7bef113669a1e7d4a8505ade.png)

---

<div class="post-metadata">

**Author:** ![chir.set](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/chir.set/32/66982_2.png) [@chir.set](https://discourse.slicer.org/u/chir.set)\
**Post date:** [August 8, 2025, 2:23pm UTC](https://discourse.slicer.org/t/issue-hiding-shapenodes-in-a-folder-via-script/44023/2 "2025-08-08T14:23:47Z")

</div>

> [@bserrano](#):
>
> the cylinders remain with `visibility=True`

This observation is expected. When you say `visibility=true`, I understand `node.GetDisplayNode().GetVisibility()`. Do you mean _screen visibility_?

The folder can hide a child markups node on screen irrespective of its visibility from the display node.

If I run your code with fiducial nodes as child items of a folder, the same observations are made.

The folder item seems to set the screen visibility of its child items without modifying the visibility member of their display nodes.

This is the good implementation. If a folder has some child nodes explicitly hidden and others visible, toggling the visibility of the folder should not change the actual visibility property of the nodes. Only the screen visibility of visible nodes will change.

---

<div class="post-metadata">

**Author:** ![bserrano](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/bserrano/32/17034_2.png) [@bserrano](https://discourse.slicer.org/u/bserrano)\
**Post date:** [August 11, 2025, 8:23am UTC](https://discourse.slicer.org/t/issue-hiding-shapenodes-in-a-folder-via-script/44023/3 "2025-08-11T08:23:30Z")

</div>

The behavior I expect is that when I run `shNode.SetItemDisplayVisibility(folderCylID, False)`, the cylinders contained in the folder hide their display in both 2D and 3D views. This is the same as what happens when you click the “eye” icon for the folder.

I don’t understand why the same code, when executed in the terminal outside of the script, does show this behavior.

---

<div class="post-metadata">

**Author:** ![chir.set](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/chir.set/32/66982_2.png) [@chir.set](https://discourse.slicer.org/u/chir.set)\
**Post date:** [August 11, 2025, 8:50am UTC](https://discourse.slicer.org/t/issue-hiding-shapenodes-in-a-folder-via-script/44023/4 "2025-08-11T08:50:45Z")

</div>

> [@bserrano](#):
>
> when executed in the terminal

You mean, outside of Slicer or Slicer’s environment? in an OS terminal?

---

<div class="post-metadata">

**Author:** ![bserrano](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/bserrano/32/17034_2.png) [@bserrano](https://discourse.slicer.org/u/bserrano)\
**Post date:** [August 11, 2025, 8:56am UTC](https://discourse.slicer.org/t/issue-hiding-shapenodes-in-a-folder-via-script/44023/5 "2025-08-11T08:56:54Z")

</div>

No, in the Python interactor in Slicer

---

<div class="post-metadata">

**Author:** ![chir.set](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/chir.set/32/66982_2.png) [@chir.set](https://discourse.slicer.org/u/chir.set)\
**Post date:** [August 11, 2025, 9:07am UTC](https://discourse.slicer.org/t/issue-hiding-shapenodes-in-a-folder-via-script/44023/6 "2025-08-11T09:07:22Z")

</div>

So, to recap:

- the nodes are not hidden when the code runs in your module/script
- the nodes are hidden when the code runs in your Slicer’s python console.

The immediate inference is that some processing in your module/script is preventing that. Without seeing more of your module/script, it would be hard to guess. May be your processing is not responsible, in which case, Slicer devs can be more helpful.

---

<div class="post-metadata">

**Author:** ![bserrano](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/bserrano/32/17034_2.png) [@bserrano](https://discourse.slicer.org/u/bserrano)\
**Post date:** [August 11, 2025, 9:43am UTC](https://discourse.slicer.org/t/issue-hiding-shapenodes-in-a-folder-via-script/44023/7 "2025-08-11T09:43:06Z")

</div>

That’s it.

In the earlier steps, the script creates a set of cylinders, converts them to models, and then to segments. These cylinder segments are then used for some processing with the `segmentEditor` module ([see related topic](https://discourse.slicer.org/t/crop-segment-using-shapenode/43822)).

After that step, I want to hide the cylinders to continue the process.

I’ll try looping over the elements in the folder and hiding the cylinders individually instead.

---

<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:** [August 11, 2025, 9:58am UTC](https://discourse.slicer.org/t/issue-hiding-shapenodes-in-a-folder-via-script/44023/8 "2025-08-11T09:58:07Z")

</div>

Please read this comment about how folder display node works

> [@How to add folder in scene?](https://discourse.slicer.org/t/how-to-add-folder-in-scene/29499/15):
>
> The folders have a special folder display node, but it is only created when you show/hide it in the Data module (you’ll notice because the color item will appear in its row). In theory you can create it programmatically, but as I see that function is not python wrapped. This is the code: pluginHandlerSingleton = slicer.qSlicerSubjectHierarchyPluginHandler.instance() folderPlugin = pluginHandlerSingleton.pluginByName('Folder') folderPlugin.createDisplayNodeForItem(folderItemID) If you need to c…

Is it possible that when you paste the code in the Python console you already clicked the show/hide of the folder in the Data module, but when you had done this from your module you hadn’t?

By the way please use the latest Slicer, we cannot really help with old versions. 5.6.2 is a year and a half old now, and there have been quite a lot of changes since then.

---

<div class="post-metadata">

**Author:** ![bserrano](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/bserrano/32/17034_2.png) [@bserrano](https://discourse.slicer.org/u/bserrano)\
**Post date:** [August 11, 2025, 1:27pm UTC](https://discourse.slicer.org/t/issue-hiding-shapenodes-in-a-folder-via-script/44023/9 "2025-08-11T13:27:44Z")

</div>

Now I understand…

I solved the problem using

```python
    slicer.app.processEvents() 
    shNode = slicer.mrmlScene.GetSubjectHierarchyNode()
    sceneItemID = shNode.GetSceneItemID()
    folderCylID = shNode.GetItemChildWithName(sceneItemID, "Cylinders")

   
    childrenItemIDs = []
    shNode.GetItemChildren(folderCylID, childrenItemIDs)
    
    for childID in childrenItemIDs:
        shNode.SetItemDisplayVisibility(childID, 0)  

```

Thanks
