Great work figuring it out!
Here is some more code depending on what people want to use. Personally I'm not a huge PyMel user and don't think it's worth using just for getting a matrix here. You could instead use xform like this:
import maya.api.OpenMaya as om2
offset_node_wm = om2.MMatrix(cmds.xform('offset_node', q=True, m=True, ws=True))
target_node_wm = om2.MMatrix(cmds.xform('target_node', q=True, m=True, ws=True))
offset_matrix = offset_node_wm * target_node_wm.inverse()
mt = om2.MTransformationMatrix(offset_matrix)
# collect the offset values
rotation_offset = [om2.MAngle(x).asDegrees() for x in mt.rotation()]
translation_offset = mt.translation(om.MSpace.kWorld)
scale_offset = mt.scale(om.MSpace.kWorld)
shear_offset = mt.shear(om.MSpace.kWorld)
Another thing you could do is skip the OpenMaya all together. In Maya 2019 it seems AD added a new function called "matrixUtil", which allows you to decompose a matrix. You can use it like the below code. Note that I had to include the math library as the rotation is returning radians and not degrees.
import maya.api.OpenMaya as om2
import math
offset_node_wm = om2.MMatrix(cmds.xform('offset_node', q=True, m=True, ws=True))
target_node_wm = om2.MMatrix(cmds.xform('target_node', q=True, m=True, ws=True))
offset_matrix = offset_node_wm * target_node_wm.inverse()
translation_offset = cmds.matrixUtil(*offset_matrix, q=True, t=True)
rotation_offset = [math.degrees(x) for x in cmds.matrixUtil(*offset_matrix, q=True, r=True)]
scale_offset = cmds.matrixUtil(*offset_matrix, q=True, s=True)
shear_offset = cmds.matrixUtil(*offset_matrix, q=True, sh=True)
- Mathias