Created
April 12, 2017 06:10
-
-
Save benmorgantd/4e8bf6b5298834b6d2b27c51ee76d8b4 to your computer and use it in GitHub Desktop.
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
import maya.cmds as cmds | |
# copy SDK from one driven node to another | |
def copySDK(): | |
# 1: Select driven object and then its driver | |
# 2: Select new driven object and then its driver | |
sel = cmds.ls(sl=1) | |
parentDriven = cmds.ls(sl=1)[0] | |
parentDriver = cmds.ls(sl=1)[1] | |
childDriven = cmds.ls(sl=1)[2] | |
childDriver = cmds.ls(sl=1)[3] | |
cmds.select(cl=1) | |
drivenAttrs = cmds.setDrivenKeyframe(parentDriven, q=1, driven=1) | |
# use copy and paste key on the driven attributes. You'll first need to establish the connection | |
# with the new SDK by setting a driven keyframe. The value doesn't matter. | |
# for each driven attr, find its driver attr' | |
for attr in drivenAttrs: | |
driverAtt = cmds.setDrivenKeyframe(attr, q=1, currentDriver=1) | |
# returns ".att" | |
strippedDrivenAtt = attr[attr.index("."):] | |
strippedDriverAtt = driverAtt[0][driverAtt[0].index("."):] | |
cmds.setDrivenKeyframe(childDriven + strippedDrivenAtt, currentDriver=childDriver + strippedDriverAtt) | |
cmds.select(parentDriven) | |
# now copy the keys from the parent to the child | |
cmds.copyKey(at=strippedDrivenAtt[1:]) | |
cmds.select(childDriven) | |
cmds.pasteKey() | |
# that will copy the tangent weights and values but it doesn't look like it'll do infinity for us | |
# but we can query that from the parent driven attr and then set it | |
inTanInfinity = cmds.setInfinity(parentDriven + strippedDrivenAtt, q=1, pri=1)[0] | |
outTanInfinity = cmds.setInfinity(parentDriven + strippedDrivenAtt, q=1, poi=1)[0] | |
cmds.setInfinity(childDriven + strippedDrivenAtt, pri=inTanInfinity, poi=outTanInfinity) | |
""" | |
Example Workflow: | |
- do SDKs on one hand | |
- do a select search (up in top bar) for *_CURL and run the script | |
- do for *_FIST and *_SPREAD and it will work correctly :) | |
parentDriver = "L_handCtrl_ANIM" | |
childDriver = "R_handCtrl_ANIM" | |
sel = cmds.ls(sl=1) | |
parentDriven = sel[0:19] | |
childDriven = sel[19:] | |
a = 0 | |
while a < len(parentDriven): | |
cmds.select(cl=1) | |
cmds.select(parentDriven[a],parentDriver,childDriven[a],childDriver,add=1) | |
copySDK() | |
a += 1 | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment