Placing of models under a hiearchy

Hi, i faced some problems while dealing with models that are under a hiearchy:

  1. How to get the absolute visibility of a model (since model.GetDisplayVisibility() will return 1 wether the hiearchy is set to visible or not),
  2. How to get the parent hiearchy of a model node and the hiearchy’s visibility
  3. How to move a model from a hiearchy to an other one
    Thanks for any inputs!
  1. You can get hierarchy visibility using this function:
  2. You can call GetItemParent to traverse parents, see
  3. SetItemParent, see
1 Like

Thanks a lot for your answer, all works fine,
a note on a bug i found is when illogical parent changing is applied (for example here setting the child as parent of its parent) makes the current windows nightly crash instead of returning an error (even when try/except is used) :

shNode = slicer.vtkMRMLSubjectHierarchyNode.GetSubjectHierarchyNode(slicer.mrmlScene)
sceneItemID = shNode.GetSceneItemID()
mainfolder_ID = shNode.CreateFolderItem(sceneItemID, "Main Folder")
subfolder_ID = shNode.CreateFolderItem(sceneItemID, "Sub Folder")
shNode.SetItemParent(subfolder_ID,mainfolder_ID) # regular hiearchy setting
    shNode.SetItemParent(mainfolder_ID, subfolder_ID) ## Makes slicer crash instead of returning an error

Doing checks may have performance impact, so some of the missing checks may be intentional. Is there any way you could make the application crash other than setting child as parent?

No, that was the only way it happened in hierarchies,

agreed but users may end up making their own checks (with more performance loss) to make the scripts safer if doing intricate re-organisations (try/except would be fine but it doesn’t prevent the crash in this case)

OK. I’ve added a ticket to track this:

1 Like

I fixed the issue. Tomorrow’s preview version should include the fix.