Auto-Leg Rig Update

Been a while, but still been working!
Here’s an update on my “Auto Leg Rig” script. At this point, everything is scripted except for the shaping of the controls.

That means all my custom scripted attributes, all my special SDK groups, everything… It’s SO helpful to rig this way. All I need to give it are locators for the joint positions and it will do the rest (as I told it to of course…)

Excited to move on at this point. I should be finishing up my rig pretty soon.

-Ben

import maya.cmds as cmds


"""
This script requires the following locators with the following names:
    hip
    knee
    ankle
    foot
    toe
    bank_L
    bank_R
    ikSwtich
They should be prefixed with either R_ or L_
"""


class StretchyLeg(object):
    def __init__(self,side):
        self.side = side
        print("# Leg Object Created")
    def makeJoints(self):
        self.hip= cmds.joint(n=self.side + "hip_IK",p=(cmds.xform(self.side + "hip",q=1,t=1)),rad=.3)
        self.knee = cmds.joint(n=self.side + "knee_IK",p=(cmds.xform(self.side + "knee",q=1,t=1)),rad=.3)
        self.ankle = cmds.joint(n=self.side + "ankle_IK",p=(cmds.xform(self.side + "ankle",q=1,t=1)),rad=.3)
        self.foot = cmds.joint(n=self.side + "foot_IK",p=(cmds.xform(self.side + "foot",q=1,t=1)),rad=.3)
        self.toe = cmds.joint(n=self.side + "toe_IK",p=(cmds.xform(self.side + "toe",q=1,t=1)),rad=.3)
        self.jointGrp_IK = cmds.group(self.hip,n=self.side + "legJoint_IK_GRP")
        cmds.select(self.hip)
        cmds.OrientJoint()

    # Get location from methods instead of static attributes. 
    def hipPos(self):
        return cmds.xform(self.hip,q=1,t=1,ws=1)
    def kneePos(self):
        return cmds.xform(self.knee,q=1,t=1,ws=1)
    def anklePos(self):
        return cmds.xform(self.ankle,q=1,t=1,ws=1)
    def footPos(self):
        return cmds.xform(self.foot,q=1,t=1,ws=1)
    def toePos(self):
        return cmds.xform(self.toe,q=1,t=1,ws=1)
        
    def IKleg(self):
        
        self.legIK = cmds.ikHandle(sj=self.hip,ee=self.ankle,sol="ikRPsolver",srp=1)
        
        
        self.legIKgrp = cmds.group(self.legIK[0],n=self.side + "legIK_GRP")
        self.legIK[0] = cmds.rename(self.legIK[0],self.side + "legIK")
        
        
        self.kneePoint = cmds.spaceLocator(n=self.side + "kneePoint")
        self.kneePointOrient = cmds.group(self.kneePoint,n=self.side + "kneePoint_ORIENT")
        cmds.xform(self.kneePointOrient,t=(self.anklePos()[0]+2,self.anklePos()[1],self.anklePos()[2]))
        
        
        cmds.poleVectorConstraint(self.kneePoint,self.legIK[0])
        cmds.setAttr(self.legIK[0] + ".twist",90)
        
        self.legGrp = cmds.group(self.jointGrp_IK,self.legIKgrp,self.kneePointOrient,n=self.side + "leg_GRP")
        self.kneePointSDK1 = cmds.group(self.kneePoint,n=self.side + "kneePoint_SDK1")
        
        
        
        
    def limbScale(self):
        return cmds.getAttr(self.legGrp + ".sx")
    def IKfoot(self):
        self.toeIK = cmds.ikHandle(sj=self.foot,ee=self.toe)
        self.toeIKgrp = cmds.group(self.toeIK[0],n=self.side + "toeIK_GRP")
        temp = cmds.rename(self.toeIK[0],self.side + "toeIK")
        self.toeIkSDK1 = cmds.group(temp,n=self.side + "toeIK_SDK1")
        self.xformPivot(self.toeIkSDK1,self.foot)
        self.footIK = cmds.ikHandle(sj=self.ankle,ee=self.foot)
        self.footIKgrp = cmds.group(self.footIK[0],n=self.side + "footIK_GRP")
        cmds.rename(self.footIK[0],self.side + "footIK")
        cmds.parent(self.footIKgrp,self.legGrp)
        cmds.parent(self.toeIKgrp,self.legGrp)
        self.ctrlGrp = cmds.group(self.footIKgrp,self.toeIKgrp,self.legIKgrp,self.kneePointOrient,n=self.side + "control_GRP")
   
    def reverseFoot(self):
        cmds.select(self.legGrp)
        self.reverseHeel = cmds.joint(p=(self.anklePos()[0],self.toePos()[1],self.anklePos()[2]),n=self.side + "reverseHeel_JNT",rad=.5)
        self.reverseToe = cmds.joint(p=(self.toePos()[0],self.toePos()[1],self.toePos()[2]),n=self.side + "reverseToe_JNT",rad=.5)
        self.reverseFoot = cmds.joint(p=(self.footPos()[0],self.footPos()[1],self.footPos()[2]),n=self.side + "reverseFoot_JNT",rad=.5)
        self.reverseAnkle = cmds.joint(p=(self.anklePos()[0],self.anklePos()[1],self.anklePos()[2]),n=self.side + "reverseAnkle_JNT",rad=.5)
        
        self.reverseFootGrp = cmds.group(self.reverseHeel,n=self.side + "reverseFoot_GRP")
        self.xformPivot(self.reverseFootGrp,self.reverseAnkle)
        
        cmds.select(self.reverseHeel)
        cmds.OrientJoint()

        cmds.parentConstraint(self.reverseToe,self.toeIKgrp,mo=1)
        cmds.parentConstraint(self.reverseToe,self.footIKgrp,mo=1)
        cmds.parentConstraint(self.reverseAnkle,self.legIKgrp,mo=1)
        
        cmds.parent(self.reverseFootGrp,self.jointGrp_IK)
        
        self.reverseHeelSDK1 = cmds.group(self.reverseHeel,n=self.side + "reverseHeel_SDK1")
        self.xformPivot(self.reverseHeelSDK1,self.reverseHeel)
        self.reverseFootSDK1 = cmds.group(self.reverseFoot,n=self.side + "reverseFoot_SDK1")
        self.xformPivot(self.reverseFootSDK1,self.foot)
        self.reverseToeSDK1 = cmds.group(self.reverseToe,n=self.side + "reverseToe_SDK1")
        self.xformPivot(self.reverseToeSDK1,self.toe)
        
        self.reverseFootSDK2 = cmds.group(self.reverseFootSDK1,n=self.side + "reverseFoot_SDK2")
        self.xformPivot(self.reverseFootSDK2,self.foot)
        self.reverseToeSDK2 = cmds.group(self.reverseToeSDK1,n=self.side + "reverseToe_SDK2")
        self.xformPivot(self.reverseToeSDK2,self.toe)
        
        
    def stretchyLeg(self):
        
        self.distDimStart = cmds.spaceLocator(n=self.side + "distDimStart")
        cmds.xform(self.distDimStart,t=(self.hipPos()[0],self.hipPos()[1],self.hipPos()[2]),ws=1)
        self.distDimEnd = cmds.spaceLocator(n=self.side + "distDimEnd")
        cmds.xform(self.distDimEnd,t=(self.anklePos()[0],self.anklePos()[1],self.anklePos()[2]),ws=1)
        cmds.select(self.distDimStart,self.distDimEnd,add=1)
        self.distDim = cmds.distanceDimension()
        cmds.select(self.distDim)
        self.distDimShape = cmds.pickWalk(d="down")[0]
        self.hipLen = cmds.getAttr(self.knee + ".tx")
        self.kneeLen = cmds.getAttr(self.ankle + ".tx")
        self.legStretchDist =  self.hipLen + self.kneeLen

        cmds.pointConstraint(self.reverseAnkle,self.distDimEnd,mo=1)
        cmds.pointConstraint(self.hip,self.distDimStart,mo=1)
        
        self.distGrp = cmds.group(self.distDimStart,self.distDimEnd,self.distDim,n=self.side + "distDim_GRP")
        cmds.parent(self.distGrp, self.legGrp)
        
        self.distScaleComp = cmds.createNode("multiplyDivide",n=self.side + "distScaleComp")
        cmds.setAttr(self.distScaleComp + ".i1x",self.legStretchDist)
        cmds.connectAttr(self.legGrp + ".sx",self.distScaleComp + ".i2x")
        
        self.currDist = cmds.createNode("multiplyDivide",n="currDist#")
        cmds.setAttr(self.currDist + ".op",2)
        cmds.connectAttr(self.distScaleComp + ".ox",self.currDist + ".i2x")
        cmds.connectAttr(self.distDimShape + ".distance",self.currDist + ".i1x")
        
        self.hipStretchLen = cmds.createNode("multiplyDivide",n=self.side + "hipStretchLen")
        cmds.connectAttr(self.currDist + ".ox", self.hipStretchLen + ".i1x")
        cmds.setAttr(self.hipStretchLen + ".i2x",self.hipLen)
        
        self.kneeStretchLen = cmds.createNode("multiplyDivide",n=self.side + "kneeStretchLen")
        cmds.connectAttr(self.currDist + ".ox", self.kneeStretchLen + ".i1x")
        cmds.setAttr(self.kneeStretchLen + ".i2x",self.kneeLen)
        
        
        self.hipStretchyCondition = cmds.createNode("condition",n=self.side + "hipstretchyCondition")
        cmds.setAttr(self.hipStretchyCondition + ".op",2)
        cmds.setAttr(self.hipStretchyCondition + ".cfr",self.hipLen)
        cmds.connectAttr(self.hipStretchLen + ".ox",self.hipStretchyCondition + ".ctr")
        cmds.connectAttr(self.currDist + ".ox",self.hipStretchyCondition + ".ft")
        cmds.setAttr(self.hipStretchyCondition + ".st",1)
        
        
        self.kneeStretchyCondition = cmds.createNode("condition",n=self.side + "kneestretchyCondition")
        cmds.setAttr(self.kneeStretchyCondition + ".op",2)
        cmds.setAttr(self.kneeStretchyCondition + ".cfr",self.kneeLen)
        cmds.connectAttr(self.kneeStretchLen + ".ox",self.kneeStretchyCondition + ".ctr")
        cmds.connectAttr(self.currDist + ".ox",self.kneeStretchyCondition + ".ft")
        cmds.setAttr(self.kneeStretchyCondition + ".st",1)
        
        cmds.connectAttr(self.hipStretchyCondition + ".ocr",self.knee + ".tx")
        cmds.connectAttr(self.kneeStretchyCondition + ".ocr",self.ankle + ".tx")
        cmds.parent(self.kneePointOrient,self.reverseHeel)
        
    
    
    def curveCube(self,loc,name):
        myCube = cmds.curve(d=1,p=[(0,0,0),(1,0,0),(1,0,1),(0,0,1),(0,0,0),
                                   (0,1,0),(1,1,0),(1,0,0),(1,1,0),
                                   (1,1,1),(1,0,1),(1,1,1),
                                   (0,1,1),(0,0,1),(0,1,1),(0,1,0)])
        cmds.CenterPivot()
        cmds.xform(myCube,t=(-.5,-.5,-.5))
        cmds.select(myCube)
        cmds.FreezeTransformations()
        cmds.setAttr(myCube + ".rotateOrder",1)
        cmds.xform(myCube,a=1,ws=1,t=loc)
        myCube = cmds.rename(myCube,name)
        cmds.FreezeTransformations()
        cmds.delete(ch=1)
        return myCube
        
    def orientJointChain(self,myJoint):
        cmds.select(myJoint)
        cmds.OrientJoint()
        jointChildren = cmds.listRelatives(myJoint,ad=1)
        endJoint = jointChildren[0]
        cmds.setAttr(endJoint + ".jointOrientX",0)
        cmds.setAttr(endJoint + ".jointOrientY",0)
        cmds.setAttr(endJoint + ".jointOrientZ",0)
        cmds.select(cl=1)
    
    def makeFKleg(self):
        cmds.select(cl=1)
        self.hip_FK= cmds.joint(n=self.side + "hip_FK",p=(cmds.xform(self.side + "hip",q=1,t=1)),rad=.3)
        self.knee_FK = cmds.joint(n=self.side + "knee_FK",p=(cmds.xform(self.side + "knee",q=1,t=1)),rad=.3)
        self.ankle_FK = cmds.joint(n=self.side + "ankle_FK",p=(cmds.xform(self.side + "ankle",q=1,t=1)),rad=.3)

        self.foot_FK = cmds.joint(n=self.side + "foot_FK",p=(cmds.xform(self.side + "foot",q=1,t=1)),rad=.3)
        self.toe_FK = cmds.joint(n=self.side + "toe_FK",p=(cmds.xform(self.side + "toe",q=1,t=1)),rad=.3)
        self.FKjointGrp = cmds.group(self.hip_FK,n=self.side + "joint_FK_GRP")
        self.FKlegJntGrp = cmds.group(self.FKjointGrp,n=self.side + "legJoint_FK_GRP")
        self.orientJointChain(self.hip_FK)
        cmds.parent(self.FKlegJntGrp,self.legGrp)
        
    def makeBindLeg(self):
        cmds.select(cl=1)
        self.hip_B= cmds.joint(n=self.side + "hip_B",p=(cmds.xform(self.side + "hip",q=1,t=1)),rad=.3)
        self.knee_B = cmds.joint(n=self.side + "knee_B",p=(cmds.xform(self.side + "knee",q=1,t=1)),rad=.3)
        self.ankle_B = cmds.joint(n=self.side + "ankle_B",p=(cmds.xform(self.side + "ankle",q=1,t=1)),rad=.3)

        self.foot_B = cmds.joint(n=self.side + "foot_B",p=(cmds.xform(self.side + "foot",q=1,t=1)),rad=.3)
        self.toe_B = cmds.joint(n=self.side + "toe_B",p=(cmds.xform(self.side + "toe",q=1,t=1)),rad=.3)
        self.jointGrp_B = cmds.group(self.hip_B,n=self.side + "joint_BIND_GRP")
        self.legJntGrp_B = cmds.group(self.jointGrp_B,n=self.side + "legJoint_BIND_GRP")
        self.orientJointChain(self.hip_B)
        self.hip_bindConst = cmds.parentConstraint(self.hip,self.hip_FK,self.hip_B)
        self.knee_bindConst = cmds.parentConstraint(self.knee,self.knee_FK,self.knee_B)
        self.ankle_bindConst = cmds.parentConstraint(self.ankle,self.ankle_FK,self.ankle_B)
        self.foot_bindConst = cmds.parentConstraint(self.foot,self.foot_FK,self.foot_B)
        
    def setupLeg(self):
        self.makeJoints()
        self.IKleg()
        
        self.IKfoot()
        self.reverseFoot()
        self.stretchyLeg()
        self.makeFKleg()
        self.makeBindLeg()
        self.jointGrp = cmds.group(self.FKlegJntGrp,self.legJntGrp_B,self.jointGrp_IK,n=self.side + "JointGRP")
        cmds.parent(self.distGrp,self.ctrlGrp)
        cmds.parent(self.jointGrp,self.legGrp)
        self.makeFKControls()
        self.makeIKControls()
        self.addXYZattr("Toe",self.side + "reverseToe_SDK1","_")
        self.addXYZattr("Foot",self.side + "reverseFoot_SDK1","__")
        self.addXYZattr("Heel",self.side + "reverseHeel_SDK1","___")
        self.addAttributes()
        self.footBank()
        self.setupIKswitch()
        self.setupStretchyLegSwitch()
        self.setupStretchFactorAttr()
        
        
    
    def makeFKControls(self):
        self.upLegCtrl = self.curveCube(self.hipPos(),self.side + "upperLeg_FK_ANIM")
        cmds.select(self.upLegCtrl + ".cv[0:15]",r=1)
        cmds.scale(.4,.4,.4,r=1,ocp=1)
        cmds.select(cl=1)
        self.lowLegCtrl = self.curveCube(self.kneePos(),self.side + "lowerLeg_FK_ANIM")
        cmds.select(self.lowLegCtrl + ".cv[0:15]",r=1)
        cmds.scale(.4,.4,.4,r=1,ocp=1)
        cmds.select(cl=1)
        self.footCtrl = self.curveCube(self.anklePos(),self.side + "foot_FK_ANIM")
        cmds.select(self.footCtrl + ".cv[0:15]",r=1)
        cmds.scale(.4,.4,.4,r=1,ocp=1)
        cmds.select(cl=1)
        self.toeCtrl = self.curveCube(self.footPos(),self.side + "toe_FK_ANIM")
        cmds.select(self.toeCtrl + ".cv[0:15]",r=1)
        cmds.scale(.4,.4,.4,r=1,ocp=1)
        cmds.select(cl=1)
        
        cmds.parent(self.toeCtrl,self.footCtrl)
        cmds.parent(self.footCtrl,self.lowLegCtrl)
        cmds.parent(self.lowLegCtrl,self.upLegCtrl)
        
        self.fkCtrl_GRP = cmds.group(self.upLegCtrl,n=self.side + "fk_ANIM")
        cmds.parent(self.fkCtrl_GRP,self.ctrlGrp)
        
        self.hipFKconst = cmds.parentConstraint(self.upLegCtrl,self.hip_FK,mo=1)
        self.kneeFKconst = cmds.parentConstraint(self.lowLegCtrl,self.knee_FK,mo=1)
        self.footFKconst = cmds.parentConstraint(self.footCtrl,self.ankle_FK,mo=1)
        self.toeFKconst = cmds.parentConstraint(self.toeCtrl,self.foot_FK,mo=1)
        
    def makeIKControls(self):
        self.ikLegCtrl = self.curveCube(self.anklePos(),self.side + "ikLeg_ANIM")
        cmds.select(self.ikLegCtrl + ".cv[0:15]",r=1)
        cmds.scale(.5,.5,.5,r=1,ocp=1)
        cmds.select(cl=1)
        cmds.parent(self.ikLegCtrl,self.ctrlGrp)
        cmds.parentConstraint(self.ikLegCtrl,self.reverseFootGrp,mo=1)
        
    def xformPivot(self,group,target):
        cmds.xform(group + ".scalePivot",a=1,ws=1,t=(cmds.xform(target,q=1,a=1,ws=1,t=1)))
        cmds.xform(group + ".rotatePivot",a=1,ws=1,t=(cmds.xform(target,q=1,a=1,ws=1,t=1)))
        
    def addXYZattr(self,name,target,longName):
        cmds.addAttr(self.ikLegCtrl,at="enum",en=(name + " Rotate"),ln=longName,k=1)
        cmds.setAttr(self.ikLegCtrl + "." + longName,lock=1)
        cmds.addAttr(self.ikLegCtrl,at="float",ln=name + "_X",k=1)
        cmds.addAttr(self.ikLegCtrl,at="float",ln=name + "_Y",k=1)
        cmds.addAttr(self.ikLegCtrl,at="float",ln=name + "_Z",k=1)
        
        cmds.connectAttr(self.ikLegCtrl + "." + name + "_X",target + ".rx")
        cmds.connectAttr(self.ikLegCtrl + "." + name + "_Y",target + ".ry")
        cmds.connectAttr(self.ikLegCtrl + "." + name + "_Z",target + ".rz")
        
        
    def footBank(self):
        self.footBank_L = cmds.spaceLocator()
        self.footBank_L = cmds.rename(self.footBank_L,self.side + "footBank_L")
        cmds.xform(self.footBank_L,a=1,ws=1,t=(cmds.xform(self.side + "bank_L",q=1,ws=1,a=1,t=1)))
        self.footBank_R = cmds.spaceLocator()
        self.footBank_R = cmds.rename(self.footBank_R,self.side + "footBank_R")
        cmds.xform(self.footBank_R,a=1,ws=1,t=(cmds.xform(self.side + "bank_R",q=1,ws=1,a=1,t=1)))
        
        cmds.parent(self.footBank_L,self.footBank_R,self.ctrlGrp)
        cmds.parent(self.footBank_L,self.footBank_R)
        
        cmds.addAttr(self.ikLegCtrl,at="float",ln="Foot_Bank",k=1)
        
        self.md1 = cmds.createNode("multiplyDivide")
        cmds.setAttr(self.md1 + ".i2x",-1)
        cmds.connectAttr(self.ikLegCtrl + ".Foot_Bank",self.md1 + ".i1x")
        
        #when the value is positive
        self.bankCond_L = cmds.createNode("condition")
        cmds.setAttr(self.bankCond_L + ".op",4)
        cmds.connectAttr(self.md1 + ".ox",self.bankCond_L + ".ft")
        cmds.connectAttr(self.md1 + ".ox",self.bankCond_L + ".ctr")
        cmds.setAttr(self.bankCond_L + ".cfr",0)
        cmds.connectAttr(self.bankCond_L + ".ocr",self.footBank_L + ".rz")
        
        #when the value is negative
        self.bankCond_R = cmds.createNode("condition")
        cmds.setAttr(self.bankCond_R + ".op",2)
        cmds.connectAttr(self.md1 + ".ox",self.bankCond_R + ".ft")
        cmds.connectAttr(self.md1 + ".ox",self.bankCond_R + ".ctr")
        cmds.setAttr(self.bankCond_R + ".cfr",0)
        cmds.connectAttr(self.bankCond_R + ".ocr",self.footBank_R + ".rz")
        
        self.bankGrp = cmds.group(self.footBank_L,self.footBank_R,n="footBank_GRP")
        
        cmds.parent(self.bankGrp,self.reverseHeelSDK1)
        cmds.parent(self.footBank_L,self.footBank_R)
        cmds.parent(self.reverseHeel,self.footBank_L)
        
       
        
        
    def addAttributes(self):
        cmds.addAttr(self.ikLegCtrl,at="enum",en=("Extra Attr"),ln="____",k=1)
        cmds.setAttr(self.ikLegCtrl + ".____",lock=1)
        cmds.addAttr(self.ikLegCtrl,at="float",k=1,ln="Toe_Wiggle")
        cmds.connectAttr(self.ikLegCtrl + ".Toe_Wiggle",self.toeIkSDK1 + ".rx")
        
        self.myFootPeel = self.footPeelSetup(self.ikLegCtrl,self.reverseToeSDK2,self.reverseFootSDK2)
        
        # knee orient attr
        cmds.addAttr(self.ikLegCtrl,at="float",k=1,ln="Knee_Orient")
        self.md2 = cmds.createNode("multiplyDivide")
        cmds.setAttr(self.md2 + ".i2x",-1)
        cmds.connectAttr(self.ikLegCtrl + ".Knee_Orient",self.md2 + ".i1x")
        self.md3 = cmds.createNode("multiplyDivide")
        cmds.setAttr(self.md3 + ".i2x",.05)
        cmds.connectAttr(self.md2 + ".ox",self.md3 + ".i1x")
        cmds.connectAttr(self.md3 + ".ox",self.kneePointSDK1 + ".tz")
        
    def setupIKswitch(self):
        driverAttr = self.side + "ikSwitch" + ".IK_FK_Blend" 
        cmds.addAttr(self.side + "ikSwitch",at="float",ln="IK_FK_Blend",max=10,min=-10,dv=-10,k=1)
        cmds.setDrivenKeyframe(self.side + "hip_B_parentConstraint1." + self.side + "hip_FKW1",cd=driverAttr,dv=10,v=1,itt="linear",ott="linear")
        cmds.setDrivenKeyframe(self.side + "knee_B_parentConstraint1." + self.side + "knee_FKW1",cd=driverAttr,dv=10,v=1,itt="linear",ott="linear")
        cmds.setDrivenKeyframe(self.side + "ankle_B_parentConstraint1." + self.side + "ankle_FKW1",cd=driverAttr,dv=10,v=1,itt="linear",ott="linear")
        cmds.setDrivenKeyframe(self.side + "foot_B_parentConstraint1." + self.side + "foot_FKW1",cd=driverAttr,dv=10,v=1,itt="linear",ott="linear")
        
        cmds.setDrivenKeyframe(self.side + "hip_B_parentConstraint1." + self.side + "hip_IKW0",cd=driverAttr,dv=10,v=0,itt="linear",ott="linear")
        cmds.setDrivenKeyframe(self.side + "knee_B_parentConstraint1." + self.side + "knee_IKW0",cd=driverAttr,dv=10,v=0,itt="linear",ott="linear")
        cmds.setDrivenKeyframe(self.side + "ankle_B_parentConstraint1." + self.side + "ankle_IKW0",cd=driverAttr,dv=10,v=0,itt="linear",ott="linear")
        cmds.setDrivenKeyframe(self.side + "foot_B_parentConstraint1." + self.side + "foot_IKW0",cd=driverAttr,dv=10,v=0,itt="linear",ott="linear")
        
        cmds.setDrivenKeyframe(self.side + "hip_B_parentConstraint1." + self.side + "hip_IKW0",cd=driverAttr,dv=-10,v=1,itt="linear",ott="linear")
        cmds.setDrivenKeyframe(self.side + "knee_B_parentConstraint1." + self.side + "knee_IKW0",cd=driverAttr,dv=-10,v=1,itt="linear",ott="linear")
        cmds.setDrivenKeyframe(self.side + "ankle_B_parentConstraint1." + self.side + "ankle_IKW0",cd=driverAttr,dv=-10,v=1,itt="linear",ott="linear")
        cmds.setDrivenKeyframe(self.side + "foot_B_parentConstraint1." + self.side + "foot_IKW0",cd=driverAttr,dv=-10,v=1,itt="linear",ott="linear")
        
        cmds.setDrivenKeyframe(self.side + "hip_B_parentConstraint1." + self.side + "hip_FKW1",cd=driverAttr,dv=-10,v=0,itt="linear",ott="linear")
        cmds.setDrivenKeyframe(self.side + "knee_B_parentConstraint1." + self.side + "knee_FKW1",cd=driverAttr,dv=-10,v=0,itt="linear",ott="linear")
        cmds.setDrivenKeyframe(self.side + "ankle_B_parentConstraint1." + self.side + "ankle_FKW1",cd=driverAttr,dv=-10,v=0,itt="linear",ott="linear")
        cmds.setDrivenKeyframe(self.side + "foot_B_parentConstraint1." + self.side + "foot_FKW1",cd=driverAttr,dv=-10,v=0,itt="linear",ott="linear")
        
    def setupStretchyLegSwitch(self):
        driverAttr = self.side + "ikSwitch" + ".Stretchy_Legs"
        cmds.addAttr(self.side + "ikSwitch",at="enum",ln="Stretchy_Legs",en="On:Off",k=1)
        cmds.setDrivenKeyframe(self.side + "distDimStart_pointConstraint1." + self.side + "hip_IKW0",cd=driverAttr,dv=0,v=1,itt="linear",ott="linear")
        cmds.setDrivenKeyframe(self.side + "distDimEnd_pointConstraint1." + self.side + "reverseAnkle_JNTW0",cd=driverAttr,dv=0,v=1,itt="linear",ott="linear")
        
        cmds.setDrivenKeyframe(self.side + "distDimStart_pointConstraint1." + self.side + "hip_IKW0",cd=driverAttr,dv=1,v=0,itt="linear",ott="linear")
        cmds.setDrivenKeyframe(self.side + "distDimEnd_pointConstraint1." + self.side + "reverseAnkle_JNTW0",cd=driverAttr,dv=1,v=0,itt="linear",ott="linear")
    
    def setupStretchFactorAttr(self):
        cmds.addAttr(self.side + "ikSwitch",at="float",ln="Stretch_Factor",k=1)
        self.stretchFactorCond = cmds.createNode("condition",n="stretchFactorCond#")
        cmds.setAttr(self.stretchFactorCond + ".op",2)
        cmds.setAttr(self.stretchFactorCond + ".cfr",1)
        cmds.connectAttr(self.currDist + ".ox",self.stretchFactorCond + ".ctr")
        cmds.connectAttr(self.currDist + ".ox",self.stretchFactorCond + ".ft")
        cmds.setAttr(self.stretchFactorCond + ".st",1)
        
        cmds.connectAttr(self.stretchFactorCond + ".ocr",self.side + "ikSwitch" + ".Stretch_Factor")
        cmds.setAttr(self.side + "ikSwitch" + ".Stretch_Factor",lock=1)
        
        
    def footPeelSetup(self,animCtrl,toeGrp,footGrp):
        self.animCtrl = animCtrl
        self.toeGrp = toeGrp
        self.footGrp = footGrp
        # create footPeel and footPeelBreak attributes
        self.footPeel = cmds.addAttr(self.animCtrl,ln="Foot_Peel",k=1,min=0)
        self.footPeelBreak = cmds.addAttr(self.animCtrl,ln="Foot_Peel_Break",k=1,min=0,dv=30)

        # Create and connect nodes for toe group
        # First make our node that finds the difference between footPeel and footPeelBreak
        self.difference1 = cmds.createNode("plusMinusAverage")
        cmds.setAttr(self.difference1 + ".op",2)
        self.condition1 = cmds.createNode("condition")
        cmds.setAttr(self.condition1 + ".op",2)
        cmds.setAttr(self.condition1 + ".cfr",0)
        self.multDivide1 = cmds.createNode("multiplyDivide")
        cmds.setAttr(self.multDivide1 + ".i2x",-1)

        # not sure what the correct short name for Foot Peel will be. Might need to make this a variable ***
        cmds.connectAttr(self.animCtrl + ".Foot_Peel",self.difference1 + ".i1[0]")
        cmds.connectAttr(self.animCtrl + ".Foot_Peel_Break",self.difference1 + ".i1[1]")

        cmds.connectAttr(self.difference1 + ".o1",self.condition1 + ".ctr")
        cmds.connectAttr(self.animCtrl + ".Foot_Peel",self.condition1 + ".ft")
        cmds.connectAttr(self.animCtrl + ".Foot_Peel_Break",self.condition1 + ".st")

        cmds.connectAttr(self.condition1 + ".ocr",self.multDivide1 + ".i1x")

        cmds.connectAttr(self.multDivide1 + ".ox",toeGrp + ".rz")

        ### now set up the nodes for the foot

        self.difference2 = cmds.createNode("plusMinusAverage")
        self.difference3 = cmds.createNode("plusMinusAverage")
        self.condition2 = cmds.createNode("condition")
        self.condition3 = cmds.createNode("condition")
        self.multDivide2 = cmds.createNode("multiplyDivide")
        cmds.connectAttr(self.animCtrl + ".Foot_Peel_Break",self.multDivide2 + ".i1x")
        cmds.setAttr(self.multDivide2 + ".i2x",2)
        cmds.setAttr(self.difference2 + ".op",2)
        cmds.setAttr(self.difference3 + ".op",2)
        cmds.setAttr(self.condition2 + ".op",2)
        cmds.setAttr(self.condition3 + ".op",2)
        cmds.connectAttr(self.animCtrl + ".Foot_Peel",self.condition2 + ".ft")
        cmds.connectAttr(self.animCtrl + ".Foot_Peel_Break",self.condition2 + ".st")
        cmds.setAttr(self.condition3 + ".ctr",0)
        cmds.connectAttr(self.animCtrl + ".Foot_Peel",self.condition3 + ".ft")



        cmds.connectAttr(self.animCtrl + ".Foot_Peel",self.difference2 + ".i1[0]")
        cmds.connectAttr(self.animCtrl + ".Foot_Peel_Break",self.difference2 + ".i1[1]")

        cmds.connectAttr(self.animCtrl + ".Foot_Peel_Break",self.difference3 + ".i1[0]")
        cmds.connectAttr(self.difference2 + ".o1",self.difference3 + ".i1[1]")

        cmds.connectAttr(self.animCtrl + ".Foot_Peel",self.condition2 + ".cfr")
        cmds.connectAttr(self.difference3 + ".o1",self.condition2 + ".ctr")

        cmds.connectAttr(self.condition2 + ".ocr",self.condition3 + ".cfr")
        cmds.connectAttr(self.multDivide2 + ".ox",self.condition3 + ".st")

        cmds.connectAttr(self.condition3 + ".ocr",footGrp + ".rz")

        
        
        
            
myLeg2 = StretchyLeg("L_")
myLeg2.setupLeg()


Advertisements
Image

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s