# AttributeError: 'NoneType' object has no attribute 'SetAndObserveTransformNodeID'

**URL:** <https://discourse.slicer.org/t/attributeerror-nonetype-object-has-no-attribute-setandobservetransformnodeid/26212>\
**Category:** Development\
**Created:** [November 13, 2022, 7:10am UTC](https://discourse.slicer.org/t/attributeerror-nonetype-object-has-no-attribute-setandobservetransformnodeid/26212 "2022-11-13T07:10:30Z")\
**Posts on this page:** 2\
**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 13, 2022, 7:10am UTC](https://discourse.slicer.org/t/attributeerror-nonetype-object-has-no-attribute-setandobservetransformnodeid/26212/1 "2022-11-13T07:10:30Z")

</div>

Dear community,  
First of all, thank you always for helping!  
I had been trying to modify the [onPrincipalAxes()](https://github.com/jmhuie/Slicer-SegmentGeometry/blob/ecefdc3b4e0e7bbb80de4409c7baab4097d69cfe/SegmentGeometry/SegmentGeometry.py#L387) of the SegmentGeometry module to fit my use.

```auto
def troubleGetName(selectedSeg):
	sourceNode = slicer.mrmlScene.GetNodeByID("vtkMRMLSegmentationNode1")
	sourceSeg = sourceNode.GetSegmentation()
	volumeNode = slicer.mrmlScene.GetNodeByID('vtkMRMLScalarVolumeNode1')
	volumeName = volumeNode.GetName()
	segmentId = sourceSeg.GetSegmentIdBySegmentName(selectedSeg)
	segmentationNode = sourceSeg.GetSegment(selectedSeg)
	displayNode = sourceNode.GetDisplayNode()
	displayNode.SetAllSegmentsVisibility(True)
	segmentationNode.SetAndObserveTransformNodeID(None)

#my segment name is "Grain"
troubleGetName("Grain")

```

And I soon came across a situation where below error happens.

> Traceback (most recent call last):  
> File “”, line 1, in   
> File “”, line 10, in troubleGetName  
> AttributeError: ‘NoneType’ object has no attribute ‘SetAndObserveTransformNodeID’

I looked up the SetAndObserveTransformNodeID on the [vtkMRMLTransformableNode Class Reference](https://apidocs.slicer.org/master/classvtkMRMLTransformableNode.html) and saw that SetAndObserveTransformNodeID is supposed to be after a vtkMRMLTransformableNode.

> bool vtkMRMLTransformableNode::SetAndObserveTransformNodeID ( const char \* transformNodeID )

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/f/a/fad32cbaf4deebb5c22bab78fd73f1694b32ac6b.jpeg)

The captured image and other people’s cases seems to be telling me that segment node can be used as the vtkMRMLTransformableNode. So I cannot figure out what went wrong.  
Can anyone please tell me what I am doing wrong?

By the way, I just have to mention how much I love this module!  
Easy to use and so convenient!!

Thank you in advance!!

\*\*\* I posted wrong error message at first, so I fixed it!! Sorry about that!!

---

<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:** [November 13, 2022, 2:59pm UTC](https://discourse.slicer.org/t/attributeerror-nonetype-object-has-no-attribute-setandobservetransformnodeid/26212/2 "2022-11-13T14:59:26Z")

</div>

Only “segmentation” is a node. A “segment” is not a node, therefore you cannot move it independently from other segments.

To transform a single segment, you need to create a new segmentation node, move the segment there, apply and harden a transform on the segmentation node, then move the segment back to the original segmentation node (and the temporary segmentation node can be removed). These may sound like a lot of steps, but all of them are very lightweight (except maybe hardening the transform, which may be somewhat computationally intensive for a non-linear warping transform).
