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

Dear community,
First of all, thank you always for helping!
I had been trying to modify the onPrincipalAxes() of the SegmentGeometry module to fit my use.

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 and saw that SetAndObserveTransformNodeID is supposed to be after a vtkMRMLTransformableNode.

bool vtkMRMLTransformableNode::SetAndObserveTransformNodeID ( const char * transformNodeID )

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

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).

3 Likes