I would like to set and control a linear transformation from python.
I created a linear transformation via the module GUI and then I changed a parameter (just to do a test).
If I run this code nothing changes in the GUI (I would expect a reset to an identity matrix):
t = slicer.mrmlScene.GetFirstNodeByName(“LinearTransform”)
m = vtk.vtkMatrix4x4()
Of course I am missing something!
Thanks a lot.
What you do is correct.
slicer.mrmlScene.GetFirstNodeByName() does not return you the transform that you expect because you have multiple transforms by that name in the scene.
If I use GetNOdeByID it works, but it’s strange, because I’m trying this into an empty scene.
By default, 3 transforms are created for some built-in nodes (cameras or slices). But other modules can create transforms by using any names any time, so
GetFirstNodeByName is only recommended for debugging or testing.
I’ll go for the ID, much safer.