# Segment Geometry Transformation using python interactor

**URL:** <https://discourse.slicer.org/t/segment-geometry-transformation-using-python-interactor/26162>\
**Category:** Support\
**Created:** [November 9, 2022, 3:09pm UTC](https://discourse.slicer.org/t/segment-geometry-transformation-using-python-interactor/26162 "2022-11-09T15:09:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hourglassnam](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/hourglassnam/32/11796_2.png) [@hourglassnam](https://discourse.slicer.org/u/hourglassnam)\
**Post date:** [November 9, 2022, 3:09pm UTC](https://discourse.slicer.org/t/segment-geometry-transformation-using-python-interactor/26162/1 "2022-11-09T15:09:20Z")

</div>

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.

```auto
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!

---

<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 1, 2022, 7:32am UTC](https://discourse.slicer.org/t/segment-geometry-transformation-using-python-interactor/26162/2 "2022-12-01T07:32:16Z")

</div>

If @jmhuie does not respond here soon then you can submit a question as an issue in the [extension’s repository](https://github.com/jmhuie/Slicer-SegmentGeometry).

---

<div class="post-metadata">

**Author:** ![jmhuie](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jmhuie/32/7086_2.png) [@jmhuie](https://discourse.slicer.org/u/jmhuie)\
**Post date:** [December 1, 2022, 8:51pm UTC](https://discourse.slicer.org/t/segment-geometry-transformation-using-python-interactor/26162/3 "2022-12-01T20:51:36Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jmhuie](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jmhuie/32/7086_2.png) [@jmhuie](https://discourse.slicer.org/u/jmhuie)\
**Post date:** [December 9, 2022, 2:45pm UTC](https://discourse.slicer.org/t/segment-geometry-transformation-using-python-interactor/26162/4 "2022-12-09T14:45:07Z")

</div>

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.

```auto
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()

```
