Python for Maya - Get object's transform matrix relative to other object's transform
from maya.api.OpenMaya import MVector, MMatrix, MPoint | |
import maya.cmds as cmds | |
def get_relative_transform (node,coordinate_space_node): | |
node_matrix = MMatrix(cmds.xform(node, q=True, matrix=True, ws=True)) | |
parent_matrix = MMatrix(cmds.xform(coordinate_space_node, q=True, matrix=True, ws=True)) | |
return (node_matrix * parent_matrix.inverse()) | |
node_a = (cmds.ls(sl=1,sn=True))[0] | |
node_b = (cmds.ls(sl=1,sn=True))[1] | |
print (get_relative_transform(node_a,node_b)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment