Thursday, July 5, 2012

dbrInsertJoints

import maya.cmds as cmds

def dbrInsertJoints( parent_child, numJoints ):
    if len(parent_child) == 2:
        parentJoint = parent_child[0]
        childJoint = parent_child[1]
    else:
        print 'dbrInsertJoints accepts only 2 joints'
         
    pTrans = cmds.xform( parentJoint, q = True, ws = True, translation = True )
    cTrans = cmds.xform( childJoint, q = True, ws = True, translation = True )
    
    njVect = [ (cTrans[0] - pTrans[0])/(numJoints + 1), (cTrans[1] - pTrans[1])/(numJoints + 1), (cTrans[2] - pTrans[2])/(numJoints + 1) ]
    curParent = parentJoint
    for i in range(numJoints):
        pTrans = cmds.xform( curParent, q = True, ws = True, translation = True )
        cmds.select(curParent, r = True)
        curParent = cmds.joint( p = ( pTrans[0] + njVect[0], pTrans[1] + njVect[1], pTrans[2] + njVect[2] ) )
        if i == numJoints - 1:
            cmds.parent( childJoint, curParent )
            cmds.select( cl = True )
        
sel = cmds.ls( sl = True, type = 'joint' )
dbrInsertJoints( sel, 4 )


Here is a quick insert joints function, select a parent joint then child and run this. Change the 4 in the call to dbrInsertJoints to insert any number of joints.

No comments:

Post a Comment