Created
October 29, 2018 19:09
-
-
Save evitolins/2f3000fa13550aeac59f312fe251bd04 to your computer and use it in GitHub Desktop.
Maya: Subdivide Joints
This file contains hidden or 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 | |
''' | |
Split joint chain between 2 joints (parent/child). | |
Usage Example: | |
jnts = cmds.ls(selection=True, type='joint') | |
subdivide_joints(jnts[0], jnts[1], 4) | |
''' | |
def subdivide_joints (jointA, jointB, segments=2): | |
newJnts = [jointA] | |
dist = cmds.getAttr('{}.tx'.format(jointB)) / segments | |
for i in xrange(1, segments): | |
newJnt = cmds.duplicate(jointA, po=True)[0] | |
if len(newJnts): | |
cmds.parent(newJnt, newJnts[-1]) | |
cmds.setAttr('{}.tx'.format(newJnt), dist) | |
else: | |
cmds.parent(newJnt, jointA) | |
newJnts.append(newJnt) | |
cmds.parent(jointB, newJnts[-1]) | |
return newJnts |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment