Delanimation

Delano Athias - Animator

Segmenting Joints with Python in Maya

In this tutorial, we'll learn how to create a Python tool to segment joint chains in Maya. Level: Beginner-Intermediate

import maya.cmds as mc
#Segment Joints - select root joint and run script
val = 5
selRoot = mc.ls(sl=True, type='joint')[0]
mc.select(selRoot, hi=True)
chain = mc.ls(sl=True)
print chain
if len(chain) > 1: 
    selChild = mc.listRelatives(selRoot, c=True)[0]
    print selChild
    tx = mc.getAttr(selChild + '.tx')
    rad = mc.getAttr(selChild + '.radius')
    mc.select(selRoot, r=True)
    for i in range(1, val):
        jnt = mc.joint(rad=rad)
        mc.move(tx/val, 0, 0, ls=True)
    lastJnt = mc.ls(sl=True, type='joint')[0]
    print lastJnt
    mc.parent(selChild, lastJnt)
else:
    mc.warning('Please select bone object')