FK Control Script

Hi!

This short script allows me to create an FK control on a bone that is properly aligned and oriented. With this, the Local Rotation Axis of the control will match that of the bone it is aimed at.

I can use this to better automate FK control setups that will allow for proper IK/FK blending.

import maya.cmds as cmds

class FK_CTRL(object):
    def __init__(self,child,target,name):
        # the child is the bone that will be driven by this fk control
        self.child = child
        # the target is the bone that follows the child joint and will be used to aim the ctrl
        self.target = target
        # name the ctrl
        self.name = name
        
        self.ctrl = cmds.circle()
        self.ctrl[0] = cmds.rename(self.ctrl[0],self.name)
        self.orientGRP = cmds.group(self.ctrl,n=self.ctrl[0] + "_ORIENT")
        
        # move the control to the location of its child joint
        cmds.xform(self.orientGRP,t=(cmds.xform(self.child,q=1,t=1,ws=1)),ws=1)
        # set rotate order to YZX
        cmds.setAttr(self.ctrl[0] + ".rotateOrder",0)
        # correctly orient the control's Local Rotation Axis with an Aim Constraint
        self.aim = cmds.aimConstraint(self.target,self.orientGRP,upVector=(0,1,0),aimVector=(1,0,0))
        cmds.delete(self.aim)
        
        self.parentConst = cmds.parentConstraint(self.ctrl,self.child,maintainOffset=1)
        
        cmds.hilite(self.ctrl)
        cmds.select(self.ctrl[0] + ".cv[0:7]",r=1)
        cmds.rotate(0,"90deg",0,eu=1,r=1)
        cmds.select(self.ctrl)
        cmds.select(cl=1)
        cmds.delete(ch=1)
   
    
"""
myCtrl1 = FK_CTRL("fk_shoulder","fk_elbow","Shoulder_ANIM")
myCtrl2 = FK_CTRL("fk_elbow","fk_wrist","Elbow_ANIM")

cmds.parent(myCtrl2.orientGRP,myCtrl1.ctrl[0])
cmds.select(cl=1)
"""
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