# Set a node as a parent for the other nodes

**URL:** <https://discourse.slicer.org/t/set-a-node-as-a-parent-for-the-other-nodes/9646>\
**Category:** Development\
**Tags:** slicerrt\
**Created:** [December 29, 2019, 6:32pm UTC](https://discourse.slicer.org/t/set-a-node-as-a-parent-for-the-other-nodes/9646 "2019-12-29T18:32:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mik](https://avatars.discourse-cdn.com/v4/letter/m/958977/32.png) [@Mik](https://discourse.slicer.org/u/Mik)\
**Post date:** [December 29, 2019, 6:32pm UTC](https://discourse.slicer.org/t/set-a-node-as-a-parent-for-the-other-nodes/9646/1 "2019-12-29T18:32:45Z")

</div>

Greetings,

How to setup vtkMRMLRTBeamNode as a parent node for a other nodes (e.g., vtkMRMLTableNode)?

The beam node observed some table node, and in the hierarchy tree view widget the drag-and-drop operation allows to put table node as a child the beam node, but how to do same thing using C++?

The code like: `shNode->SetItemParent( tableNodeId, beamNodeId) ` doesn’t work even if all item IDs are valid.

The result should look like on the After picture.

Before

 ![HierarchyBefore](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/b/8/b837522059f81295efbf42739353155ed0b436c6.png)

After

 ![HierarchyAfter](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/4/b/4b5030247033547d70543af7cea1c128d6aa26af.png)

---

<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:** [December 29, 2019, 7:16pm UTC](https://discourse.slicer.org/t/set-a-node-as-a-parent-for-the-other-nodes/9646/2 "2019-12-29T19:16:28Z")

</div>

`SetItemParent` method should work well. Use subject hierarchy item IDs (not MRML node IDs) as inputs. Make sure you use latest stable or latest preview release.

---

<div class="post-metadata">

**Author:** ![Mik](https://avatars.discourse-cdn.com/v4/letter/m/958977/32.png) [@Mik](https://discourse.slicer.org/u/Mik)\
**Post date:** [December 30, 2019, 6:16pm UTC](https://discourse.slicer.org/t/set-a-node-as-a-parent-for-the-other-nodes/9646/3 "2019-12-30T18:16:10Z")

</div>

Could it be that batch process state of the scene prevent such operation? It works well after `scene->EndState(vtkMRMLScene::BatchProcessState);`.

---

<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:** [December 30, 2019, 6:45pm UTC](https://discourse.slicer.org/t/set-a-node-as-a-parent-for-the-other-nodes/9646/4 "2019-12-30T18:45:53Z")

</div>

There are limited or no widget updates while in batch processing state, but after batch processing ends, all the pending changes should be applied.
