SetItemDisplayVisibility works only occasionally

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.

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()’

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.

1 Like

Thank you for the explanation!

I then found more out here: Script repository — 3D Slicer documentation

(Maybe it is useful for future readers.)

1 Like