Save transformation matrix programmatically after landmark registration

Operating system: Win10
Slicer version:4.10.2
Expected behavior:
Actual behavior:

Hi guys,
I am new to slicer programming. I am loading two volume data( fixed and moving one). Then using slicer’s landmark registration module and selecting some landmark.
After registration is done I want to save the transformation matrix programmatically. If possible getting the transformation matrix after every landmark is selected.
can you please provide an example to do that?

Thanks

You can save node to file using slicer.util.saveNode() method. Slicer saves transforms in ITK transform file format (binary .h5 file or text .txt file).

I used it like below lines:
>>> slicer.util.saveNode(transformNode,“C:\Users\Johar\Desktop\CheckIT\transmat.txt”)
> False
And as you can see, I get nothing. Can you correct me and show, how to get the transform node correctly and then save?

Use forward slashes not backslashes :wink:

You can also use raw strings (add an r character before the string literal), to prevent interpreting backslash as an escape character:

slicer.util.saveNode(transformNode,r"C:\Users\Johar\Desktop\CheckIT\transmat.txt")

Hi @lassoan and @pieper
I tried both of your ideas. But I think I am not catching the transform node correctly.

>>> slicer.util.saveNode("Transform",r"C:/Users/transmat.txt")
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "C:\Slicer 4.10.2\bin\Python\slicer\util.py", line 512, in saveNode
    properties["nodeID"] = node.GetID();
AttributeError: 'str' object has no attribute 'GetID'  

This is how transform matrix looks like after landmark registration:
Unbenannt

“Transform” is the node’s name. You can use slicer.util.getNode() method to get the node object from its name:

slicer.util.saveNode(slicer.util.getNode("Transform"),r"C:/Users/transmat.txt")

Please complete one of the Slicer programming tutorials. All these basic concepts are described there.