Copying translations and rotations to offsetParentMatrix
Recently I watched the chapter Scripting offset parent matrices on 3D Animation and Rigging Weekly and a MEL script was used to automate the copying of values from matrix to offsetParentMatrix followed by resetting the matrix to identity.
I have written the following code to achieve the same using PyMel (I have also added some boiler plate code to flag errors)
import pymel.core as pm
def copy_matrix_to_offsetParentMatrix(control):
try:
control.matrix.connect(control.offsetParentMatrix)
except Exception as e:
print e
print control.name(), "Cannot connect to offsetParentMatrix"
try:
control.matrix.disconnect(control.offsetParentMatrix)
except Exception as e:
print e
print control.name(), "Cannot disconnect from offsetParentMatrix"
def reset_translate_rotate(control):
channels = "translateX translateY translateZ rotateX rotateY rotateZ"
for channel in channels.split():
control.attr(channel).set(0)
if __name__ = "__main__":
controls = pm.selected()
if not controls:
raise ValueError("Nothing selected")
for control in controls:
copy_matrix_to_offsetParentMatrix(control)
reset_translate_rotate(control)You can find a copy of the code on my GitHub as well.
Maya/workflow/rigging/ctrl_copyreset_matrix_to_offsetParentMatrix.py
And if you are not aware of Offset Parent Matrices, then you could watch the video below.
Thank you.
S
I really appreciate the kind of topics posted here. Thanks for sharing great information that is actually helpful. Good day! Autodesk Maya Crack
ReplyDelete