Skip to content

Instantly share code, notes, and snippets.

@mottosso
Last active May 11, 2016 20:39
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 mottosso/a99aea9d408a1859cd23 to your computer and use it in GitHub Desktop.
Save mottosso/a99aea9d408a1859cd23 to your computer and use it in GitHub Desktop.
# Mirror transform
from maya import cmds
def mirror_transforms(nodes):
"""Mirror transforms `nodes` across the YZ axis
Arguments:
nodes (list): Transforms to be mirrored
"""
for node in nodes:
temp_joint = cmds.createNode('joint')
temp_ctl = cmds.duplicate(node,
inputConnections=True,
returnRootsOnly=True)
cmds.parent(temp_joint, node)
cmds.parent(temp_joint, world=True)
cmds.parent(temp_ctl, temp_joint)
mirrored = cmds.mirrorJoint(temp_joint,
mirrorBehavior=True,
mirrorYZ=True)
mirrored_joint = mirrored.pop(0)
mirrored_ctl = mirrored.pop(0)
cmds.parent(mirrored_ctl, world=True)
cmds.delete([temp_joint, temp_joint, mirrored_joint])
yield node, mirrored_ctl
def mirror_shapes(nodes):
"""In addition to mirroring transforms, also mirror shapes
Arguments:
nodes (list): Transforms with shapes to mirror
"""
for original, mirrored in mirror_transforms(nodes):
mirrored_original = cmds.duplicate(original,
name=original + "_duplicate")
mirrored_group = cmds.createNode('transform',
name=original + "_transform")
cmds.parent(mirrored_original[0], mirrored_group)
cmds.setAttr(mirrored_group + ".sx", -1)
blendshape = cmds.blendShape((mirrored_original[0], mirrored),
origin='world')
cmds.setAttr(blendshape[0] + "." + mirrored_original[0], 1)
mirrored_with_shape = cmds.duplicate(mirrored)
cmds.delete([mirrored, mirrored_group])
cmds.select(mirrored_with_shape, replace=True)
def mirror_selected_transforms():
"""Interactively mirror transforms"""
nodes = cmds.ls(sl=1,
objectsOnly=True,
type='transform',
long=True)
for node in mirror_transforms(nodes):
pass
def mirror_selected_shapes():
"""Interactively mirror shapes"""
nodes = cmds.ls(sl=1,
objectsOnly=True,
type='transform',
long=True)
return mirror_shapes(nodes)
@mottosso
Copy link
Author

Hijack the Mirror Joint feature of Maya to mirror controls across the YZ axis.

@mottosso
Copy link
Author

Now also mirrors shapes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment