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?
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.
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.
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.
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).
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.
Please read this comment about how folder display node works
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.