How to turn off the visibility of 3D models

Hope you are doing well!
As shown in figure below, I’ve created a ‘Segmentation’ node for ‘MRHead’ which contains two segments: Segment_1(with threshold 50-279), Segment_2(with threshold 80-279).

  1. I imported this segmentation node into the model module using the following code:
shNode = slicer.mrmlScene.GetSubjectHierarchyNode()
exportFolderItemId = shNode.CreateFolderItem(shNode.GetSceneItemID(), 'HEAD')
segmentationNode1 = getNode("Segmentation")
slicer.modules.segmentations.logic().ExportAllSegmentsToModels(segmentationNode1, exportFolderItemId)

But after I run the above code, the models’ visibility of the two segments are turned on by default. How to turn off the visibility of the two segmented models using python separately?

  1. How to remove a segment in this segmentation node programmatically? For example, how to delete the second segment node(Segment_2)?

Grateful for your help in advance!

See how to iterate through the nodes in the subject hierarchy folder in this example.

You can hide a model node by calling modelNode.GetDisplayNode().SetVisibility(False).

It is probably better not to export the node in the first place. You can achieve that by using ExportSegmentsToModels that takes a segment ID list; or hiding the segments you don’t want to export and use ExportVisibleSegmentsToModels.

1 Like