Skip to content

Instantly share code, notes, and snippets.

@CGLion
Last active March 23, 2024 04:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save CGLion/5149f7fd81797a4eab468c35a9026ee8 to your computer and use it in GitHub Desktop.
Save CGLion/5149f7fd81797a4eab468c35a9026ee8 to your computer and use it in GitHub Desktop.
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