How to access child node

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

Hello @aldoSanchez

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#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

1 Like

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.

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