Reversed foot

Started writing a script for making a reversed foot during lecture (yes I get bored really fast when I listen to people talk) and here’s the result. Still very much a work in progress, so might be a little rough around the edges. Anyway. Instructions for getting it to work:

1) select all and add to shelf as a python script
2) execute and press the first button
3) place the locators at their appropriate positions
4) execute step 2
5) select your foot control and execute the third and last step

.. and voila (hopefully)! There should now be a bunch of custom attributes on the foot control. Let me know if it bugs out anywhere (jonne@jonne.net). Change side = ‘L_’ to side = ‘R_’ if you for some strange reason need to do the other side to …

##
## reversedFoot
## -------------
## 24 sep 2009
## Jan-Erik "Jonne" Östman (jonne@jonne.net)
##
## www.jonne.net
##
## Description:
## ------------
## PYTHON script for creating a reversed foot
##
##
## Instructions:
## -------------
## Run the script. Click the first button to create a bunch of locators.
## Place those at their appropriate positions. Klick the second button to 
## create the heirarchy etc. Select your foot control and execute the last 
## step to create the SDK's 
##
## -------------------------------------------------------------------------

import maya.cmds as mc

#global vars
side = 'L_'
locs = [side + 'hip_JNT',side + 'knee_JNT',side + 'heel_JNT', side + 'ball_JNT', side + 'toe_JNT']
grpLocs = [side + 'heelPivot_GRP', side + 'toePivot_GRP', side + 'toeTap_GRP', side + 'peelHeel_GRP']

#gets selected object as control object
def getCtrlObj():
	foo = mc.ls(sl=1)
	ctrlObj = foo[0] #side + 'foot_CTRL' #'nurbsCircle1'
	return ctrlObj

#reset the footcontrol after it's been created
def resetFootCtrl():
	mc.setAttr(getCtrlObj() + ".peelHeel", 0)
	mc.setAttr(getCtrlObj() + ".standTip", 0)
	mc.setAttr(getCtrlObj() + ".twistHeel", 0)
	mc.setAttr(getCtrlObj() + ".twistToes", 0)
	mc.setAttr(getCtrlObj() + ".toeTap", 0)

#set driven keys
def setSDK(driverObj, driverVal, drivenObj, drivenVal, valueToDrive):
	mc.setAttr(getCtrlObj()+ "." + driverObj,driverVal) #set control attribute
	mc.setAttr(drivenObj + "." + valueToDrive,drivenVal) #set behavior
	mc.setDrivenKeyframe(drivenObj + "." + valueToDrive, cd=getCtrlObj()+"." + driverObj )

#move pivot to selected position
def setPivot(locatorPos, groupToMove):
	grpPos = mc.xform(locs[locatorPos], q=1, ws=1, rp=1)
	mc.move(grpPos[0],grpPos[1],grpPos[2], grpLocs[groupToMove])

#get joint position
def getPos(jnt):
	foo = mc.xform(jnt, q=1, t=1)
	return foo

#create locators
def createLocs():
	for i in locs:
		mc.spaceLocator(n=i+"_LOC")


#----------------------------
# Step 1. Create joints and hierarchy
#----------------------------
def createJoints():
	#clear selection
	mc.select(cl=1)

	#place joints
	for i in locs:
		jntPos = getPos(i+"_LOC")
		mc.joint( n=i, p=jntPos,)

	#orient joints
	mc.select(locs[0], r=1)
	#userinput
	mc.joint( edit=1, ch=1, oj='xyz', sao='yup' )

	#create IK's
	mc.ikHandle(sol='ikRPsolver', n=side + 'heel_IK',sj=locs[0], ee=locs[2])
	mc.ikHandle(sol='ikSCsolver', n=side + 'ball_IK',sj=locs[2], ee=locs[3])
	mc.ikHandle(sol='ikSCsolver', n=side + 'toe_IK',sj=locs[3], ee=locs[4])

	#create groups
	for i in grpLocs:
		mc.group(em=1, n=i)

	#move group pivot's to locator/joint
	setPivot(2,0)	#heel pivot
	setPivot(3,2)	#toeTap
	setPivot(4,1)	#toePivot
	setPivot(3,3)	#peelHeel

	#create hierarchy with groups and the IK's
	mc.parent(grpLocs[2], grpLocs[1])
	mc.parent(grpLocs[3], grpLocs[1])
	mc.parent(grpLocs[1], grpLocs[0])

	mc.parent(side + 'heel_IK', grpLocs[3])
	mc.parent(side + 'ball_IK',grpLocs[2])
	mc.parent(side + 'toe_IK',grpLocs[2])


#------------------------------------------------------
# Step 2.
# Add attributes to selected foot control and set SDK's
#------------------------------------------------------
def createSDK():

	#add attributes to control
	mc.addAttr(getCtrlObj(),ln='peelHeel', at="float", min=0, max=10, dv=0, k=1, h=0)
	mc.addAttr(getCtrlObj(),ln='standTip', at="float", min=0, max=10, dv=0, k=1, h=0)
	mc.addAttr(getCtrlObj(),ln='twistHeel', at="float", min=-10, max=10, dv=0, k=1, h=0)
	mc.addAttr(getCtrlObj(),ln='twistToes', at="float", min=-10, max=10, dv=0, k=1, h=0)
	mc.addAttr(getCtrlObj(),ln='toeTap', at="float", min=-10, max=10, dv=0, k=1, h=0)

	#Create sdk's
	#Peel heel
	setSDK("peelHeel", 0, grpLocs[3], 0, "rotateX")
	setSDK("peelHeel", 10, grpLocs[3], 45, "rotateX")

	#Toe tap
	setSDK("toeTap",0, grpLocs[2], 0, "rotateX")
	setSDK("toeTap",10, grpLocs[2], 40, "rotateX")
	setSDK("toeTap",-10, grpLocs[2], -30, "rotateX")

	#standTip
	setSDK("standTip",0, grpLocs[1], 0, "rotateX")
	setSDK("standTip",10, grpLocs[1], 55, "rotateX")

	#twistHeel
	setSDK("twistHeel",0, grpLocs[1], 0, "rotateY")
	setSDK("twistHeel",10, grpLocs[1], -35, "rotateY")
	setSDK("twistHeel",-10, grpLocs[1], 35, "rotateY")

	#twistToes
	setSDK("twistToes",0, grpLocs[0], 0, "rotateY")
	setSDK("twistToes",10, grpLocs[0], -45, "rotateY")
	setSDK("twistToes",-10, grpLocs[0], 45, "rotateY")

	resetFootCtrl()


#------------------------------------------------------
# DISPLAY WINDOW
#------------------------------------------------------
window = mc.window( title="Long Name", iconName='Short Name', widthHeight=(150, 70) )
mc.columnLayout( adjustableColumn=True )

mc.button( label='1. Create locators', command=('createLocs()') )
mc.button( label='2. Create joints and hierarchy', command=('createJoints()') )
mc.button( label='3. Select footControl and creates SDK', command=('createSDK()') )

mc.button( label='Close', command=('mc.deleteUI(\"' + window + '\", window=True)') )
mc.setParent( '..' )
mc.showWindow( window )

I wish to do something Great and Wonderful, but I must start by doing the little things like they were Great and Wonderful”
~ Albert Einstein