Skip to content

Instantly share code, notes, and snippets.

@evitolins
Created October 29, 2018 19:09
Show Gist options
  • Save evitolins/2f3000fa13550aeac59f312fe251bd04 to your computer and use it in GitHub Desktop.
Save evitolins/2f3000fa13550aeac59f312fe251bd04 to your computer and use it in GitHub Desktop.
Maya: Subdivide Joints
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