Last active
March 23, 2024 04:46
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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