Segment Geometry Transformation using python interactor

Hello~!
I was trying to use Segment Geometry using python interactor.
I figure out how to get the statistic data but could not make the transformation to work.

I tried below script and got following error message.

import SegmentGeometry
SegGeoLogic = SegmentGeometry.SegmentGeometryLogic()
SegGeoLogic.getParameterNode().SetParameter(volumeName, sourceNode.GetID())
slicer.modules.SegmentGeometryWidget.onPrincipalAxes()

Traceback (most recent call last):
File “”, line 1, in
File “C:/Users/njy95/AppData/Local/NA-MIC/Slicer 5.1.0-2022-09-27/NA-MIC/Extensions-31161/SegmentGeometry/lib/Slicer-5.1/qt-scripted-modules/SegmentGeometry.py”, line 395, in onPrincipalAxes
segName = segmentationNode.GetName()
AttributeError: ‘NoneType’ object has no attribute ‘GetName’

I thought I did setup Segmentation node for the transformation, so I cannot figure out what went wrong!

I will be glad to hear any advice on how to use the onPrincipalAxes for the Segment Geometry Transformation.
Thank you in advance!

If @jmhuie does not respond here soon then you can submit a question as an issue in the extension’s repository.

1 Like

I’ll admit that I have not tested how well SegmentGeometry works using the python terminal. I will see if I can get to the root of the problem and get back to you @hourglassnam.

2 Likes

Hi @hourglassnam

When using the sample data for SegmentGeometry, this chunk of code worked for me. Give this ago and let me know if it doesn’t work. You’ll need to define the volumenode, the segmentation node, and the segment you want to use.

volumeNode = getNode("DemoForelimb")
segmentationNode = getNode("DemoSegment")

slicer.modules.segmentgeometry.widgetRepresentation()
slicer.modules.SegmentGeometryWidget.ui.segmentationSelector.setCurrentNode(segmentationNode)
slicer.modules.SegmentGeometryWidget.ui.regionSegmentSelector.setCurrentSegmentID("Humerus")
slicer.modules.SegmentGeometryWidget.ui.volumeSelector.setCurrentNode(volumeNode)
slicer.modules.SegmentGeometryWidget.onPrincipalAxes()