# Placing of models under a hiearchy

**URL:** https://discourse.slicer.org/t/placing-of-models-under-a-hiearchy/8587
**Category:** Development
**Created:** [September 27, 2019, 8:52am UTC](https://discourse.slicer.org/t/placing-of-models-under-a-hiearchy/8587 "2019-09-27T08:52:27Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Amine](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/amine/32/4844_2.png) [@Amine](https://discourse.slicer.org/u/Amine)
#### Post date: [September 27, 2019, 8:52am UTC](https://discourse.slicer.org/t/placing-of-models-under-a-hiearchy/8587/1 "2019-09-27T08:52:28Z")

</div>

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!

---

<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: [September 27, 2019, 1:34pm UTC](https://discourse.slicer.org/t/placing-of-models-under-a-hiearchy/8587/2 "2019-09-27T13:34:12Z")

</div>

1. You can get hierarchy visibility using this function: [https://github.com/Slicer/Slicer/blob/master/Libs/MRML/Core/vtkMRMLFolderDisplayNode.h#L90](https://github.com/Slicer/Slicer/blob/master/Libs/MRML/Core/vtkMRMLFolderDisplayNode.h#L90)
2. You can call GetItemParent to traverse parents, see [https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Subject\_hierarchy](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Subject_hierarchy)
3. SetItemParent, see [https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Manipulate\_subject\_hierarchy\_item](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Manipulate_subject_hierarchy_item)

---

<div class="post-metadata">

### Author: ![Amine](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/amine/32/4844_2.png) [@Amine](https://discourse.slicer.org/u/Amine)
#### Post date: [September 27, 2019, 10:05pm UTC](https://discourse.slicer.org/t/placing-of-models-under-a-hiearchy/8587/3 "2019-09-27T22:05:49Z")

</div>

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
try:
    shNode.SetItemParent(mainfolder_ID, subfolder_ID) ## Makes slicer crash instead of returning an error
except:
    pass
```

---

<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: [September 28, 2019, 8:54pm UTC](https://discourse.slicer.org/t/placing-of-models-under-a-hiearchy/8587/4 "2019-09-28T20:54:21Z")

</div>

> [@Amine](#):
>
> 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

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?

---

<div class="post-metadata">

### Author: ![Amine](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/amine/32/4844_2.png) [@Amine](https://discourse.slicer.org/u/Amine)
#### Post date: [September 28, 2019, 11:49pm UTC](https://discourse.slicer.org/t/placing-of-models-under-a-hiearchy/8587/5 "2019-09-28T23:49:24Z")

</div>

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

> [@lassoan](#):
>
> Doing checks may have performance impact

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)

---

<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: [October 2, 2019, 12:57am UTC](https://discourse.slicer.org/t/placing-of-models-under-a-hiearchy/8587/6 "2019-10-02T00:57:27Z")

</div>

OK. I’ve added a ticket to track this: [https://issues.slicer.org/view.php?id=4713](https://issues.slicer.org/view.php?id=4713)

---

<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: [October 2, 2019, 6:26pm UTC](https://discourse.slicer.org/t/placing-of-models-under-a-hiearchy/8587/7 "2019-10-02T18:26:02Z")

</div>

I [fixed](https://github.com/Slicer/Slicer/commit/ff7b83fc542497092a3aa127d5e7c45c98e9208b) the issue. Tomorrow’s preview version should include the fix.
