splinecraft
4/5/2017 - 8:14 PM

From http://www.conghal.com/blog/ quadruped create pivot control for baked quadruped locators (step 2)

From http://www.conghal.com/blog/ quadruped create pivot control for baked quadruped locators (step 2)

#create pivot ctrls for selected locators

import maya.cmds as cmds

rawSel = cmds.ls (sl=True)
sel=[]

for i in rawSel:
    if (cmds.objectType(i) == "objectSet"):
        sel += cmds.sets(i, q=True)
    else:
        sel.append(i)

radCircle = cmds.circle(nr=(0,1,0), n="radiusPivot_circle")
radLoc =  radCircle[0] #cmds.spaceLocator (n="masterRadius_locator")[0]
cmds.addAttr (radLoc, ln="cycleDistance", at="double", k=True, dv=132)
cmds.addAttr (radLoc, ln="cycleAngle", at="double", k=True, dv=120)

pivotLoc = cmds.spaceLocator (n="radiusPivot_locator")[0]
pivotLoc = cmds.parent(pivotLoc, radLoc)[0]

expString = "tx = ({0}.cycleDistance * 180)/({0}.cycleAngle * 3.141592653589793)".format(radLoc)
cmds.expression(o=pivotLoc, s=expString)

cmds.connectAttr(pivotLoc + ".tx", radCircle[1] + ".radius", f=True)
cmds.connectAttr(pivotLoc + ".tx", radCircle[1] + ".centerX", f=True)

for loc in sel:
    posDriver = cmds.group(em=True, n=loc + "_posDrvGrp")
    cmds.parent(loc, posDriver)
    expString = "tx = -1 * ({0}.tx + {1}.tx)".format(radLoc, pivotLoc)
    cmds.expression(o=posDriver, s=expString)
    expString = "tz = -1 * {0}.tz".format(loc)
    cmds.expression(o=posDriver, s=expString)
    
    rotDriver = cmds.group(em=True, n=loc + "_rotDrvGrp")
    cmds.parent(posDriver, rotDriver)
    rotDriver = cmds.parent(rotDriver, pivotLoc, r=True)[0]
    expString = "ry = ({0}.tz * 180) / ({1}.tx * 3.141592653589793)".format(loc, pivotLoc)
    cmds.expression(o=rotDriver, s=expString)