Created
September 30, 2014 07:42
-
-
Save mottosso/4e69ef55b308c4d766f7 to your computer and use it in GitHub Desktop.
Mirror channel values across controllers
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
""" | |
Given a node following the convention <side>_<name>_<suffix>, look for an | |
equivalent side with matching suffix and transfer attribute values across. | |
.. note:: This assumes controllers are mirrored by *behaviour*; i.e. | |
Identical values produce mirrored results. | |
""" | |
def mirror_control(ctrl): | |
"""Given a control, look up its side and transfer values to other side""" | |
opposites = {'L': 'R', 'R': 'L'} | |
side, name = ctrl.split("_", 1) | |
opposite_ctrl = "%s_%s" % (opposites[side], name) | |
for channel in ('translate', 'rotate', 'scale'): | |
for axis in 'XYZ': | |
value = cmds.getAttr("{name}.{chan}{ax}".format( | |
name=ctrl, chan=channel, ax=axis)) | |
cmds.setAttr("{name}.{chan}{ax}".format( | |
name=opposite_ctrl, chan=channel, ax=axis), value) | |
def hierarchy(ctrl): | |
"""Get hierarchy of `ctrl` with matching suffix""" | |
typ = cmds.nodeType(ctrl) | |
name, suffix = ctrl.rsplit("_", 1) | |
descendents = list() | |
for descendent in cmds.listRelatives(ctrl, | |
allDescendents=True, | |
type=typ): | |
if not descendent.endswith(suffix): | |
continue | |
descendents.append(descendent) | |
return [ctrl] + descendents | |
for node in cmds.ls(sl=1): | |
for ctrl in hierarchy(node): | |
mirror_control(ctrl) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment