# How to access child node

**URL:** <https://discourse.slicer.org/t/how-to-access-child-node/13866>\
**Category:** Support\
**Tags:** segmentation, python\
**Created:** [October 5, 2020, 2:31pm UTC](https://discourse.slicer.org/t/how-to-access-child-node/13866 "2020-10-05T14:31:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![aldoSanchez](https://avatars.discourse-cdn.com/v4/letter/a/5f9b8f/32.png) [@aldoSanchez](https://discourse.slicer.org/u/aldoSanchez)\
**Post date:** [October 5, 2020, 2:31pm UTC](https://discourse.slicer.org/t/how-to-access-child-node/13866/1 "2020-10-05T14:31:02Z")

</div>

how can i access child node by code.  
for example :  
the Segmentation node  
has child nodes:  
Left-Cerebral-White-Matter  
Left-Cerebral-Cortex  
…

---

<div class="post-metadata">

**Author:** ![Andinet\_Enquobahrie](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/andinet_enquobahrie/32/75_2.png) [@Andinet\_Enquobahrie](https://discourse.slicer.org/u/Andinet_Enquobahrie)\
**Post date:** [October 7, 2020, 11:55am UTC](https://discourse.slicer.org/t/how-to-access-child-node/13866/2 "2020-10-07T11:55:35Z")

</div>

Hello @aldoSanchez

> [@aldoSanchez](#):
>
> how can i access child node by code.  
> for example :  
> the Segmentation node  
> has child nodes:  
> Left-Cerebral-White-Matter  
> Left-Cerebral-Cortex  
> …

There are python snippets that you can use to do this in the Script repository

[https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Get\_subject\_hierarchy\_item](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Get_subject_hierarchy_item)  
[https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Traverse\_children\_of\_a\_subject\_hierarchy\_item](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Traverse_children_of_a_subject_hierarchy_item)

If you need to manipulate segments in the segmentation container, you can do something like the following

```
 segmentNames = ["Prostate", "Urethra"]
 segmentIds = vtk.vtkStringArray()
 for segmentName in segmentNames:
     segmentId = 
        segmentationNode.GetSegmentation().GetSegmentIdBySegmentName(segmentName)
        segmentIds.InsertNextValue(segmentId)
 
 slicer.vtkSlicerSegmentationsModuleLogic.ExportSegmentsToLabelmapNode(segmentationNode, segmentIds, labelmapVolumeNode, referenceVolumeNode)

```

-Andinet

---

<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 7, 2020, 12:18pm UTC](https://discourse.slicer.org/t/how-to-access-child-node/13866/3 "2020-10-07T12:18:08Z")

</div>

Please note that in the case of segmentations, the segments are not actual nodes, but part of the segmentation node. So instead of using subject hierarchy functions for getting the children, you need to access the segments within the segmentations as @Andinet_Enquobahrie suggests.

---

<div class="post-metadata">

**Author:** ![aldoSanchez](https://avatars.discourse-cdn.com/v4/letter/a/5f9b8f/32.png) [@aldoSanchez](https://discourse.slicer.org/u/aldoSanchez)\
**Post date:** [October 7, 2020, 2:22pm UTC](https://discourse.slicer.org/t/how-to-access-child-node/13866/4 "2020-10-07T14:22:17Z")

</div>

what i did was to export the segmentation to modules  
and now I want to manipulate the colors and the visibility of the modules.
