Although this is a piece of code. It’s good for anyone who wants to start coding in maya or learning rigging, as you can de-piece the code to find out what I’ve done.

In my first semester of second year, we had modules we had to pick. Out of rigging, tech hack and coding, I picked coding. For my coding project we were required to make a piece of code fixing a problem or a way to save time in maya.

Since I attended the rigging classes as well I decided making a tool that would save time in rigging. One lesson we had was about reverse foot rigs considering this seemed to be the hardest thing for people to grasp I felt it made sense to made a code that would do it automatically based on joints made in the scene. Alongside this we had to made a read me document to explain how to use the tool and what it does. So below is my read me document and below that is the tool itself.

 

Reverse Foot Tool
*****************
This tool creates the joints for a reverse foot based on the leg already made in the scene. Allowing
a reverse foot to be made in any scene with a click of a button saving a lot of time.
Instructions
************
First create the leg joints, which include the leg, knee, ankle, ball and toe. After creating this
run the code to create the window.

There is one drop down menu and 3 buttons in the tool.

To allow the tool to use your chosen joints you have to select each joint and save it to a name in the
drop down menu. The tool allows the user to select the joint in maya or from the drop down menu first
(eg. click the created ankle joint in the scene then the Ankle_Joint from the drop down menu).After
both are chosen “click select the joint”. Then repeat this process for each joint in the drop
down menu.

Since you could easily accidentally save the wrong joint to the name another button underneath called
“Check if all items are selected” which after it is clicked will print 5 lines in the script editor
telling you if and what is assigned to each choice in the drop down menu. If anything is wrong you
can repeat the process above to change the joint as the saved selection will only allow one item at
a time.

After getting all the right joints selected you then can click “Make the reverse foot” which will
create the reverse foot.
Specifics of the reverse foot
*****************************
First the tool creates IKHandles throughout the leg, going from the Leg to ankle, Ankle to ball and
Ball to toe.

Then it recreates the toe, ball and ankle joints in the exact same place, but the heirarchy
is reversed. Hence the name reverse foot. Another addition is a heel joint is created based on the
XY co-ordinates of the ankle joint and the Y co-ordinates of the toe joint.

After creating the reverse foot joints the IKhandles created at the start are parented into the
reverse foot joints.

With that done the reverse foot is created.

*****************************

 

import maya.cmds as cmds

Selected=0

def StoreSelectedControl(item):
global selecteditem
selecteditem = item
print (“Item selected = ” + selecteditem)
#Allows the select to default for the menu
selecteditem =’Ankle_Joint’

#DropDownList information
dropdownList=[] dropdownListdefi = {‘Ball_Joint’:0, ‘Toe_Joint’:0, ‘Leg_Joint’:0, ‘Knee_Joint’:0, ‘Ankle_Joint’:0}

#Saves the joint so it can be used later on
def SelectJoint(*args):
global aim
aim = cmds.ls( sl=True )
global selecteditem
print(“Count =” + str(len(aim)))
if len(aim)==1:
dropdownList.append(selecteditem) # keeping this for debugging purposes
dropdownListdefi[selecteditem]=aim[0] else:
print(“Please have one joint selected”)

#Allows the User to check if they have got a selection to the name and what is assigned
def CheckingIfSelected(*args):
global Selected
global dropdownListdefi
global dropdownList
for item in dropdownList:
print( “dropdownList” +item)
for key, value in dropdownListdefi.iteritems():
if value == 0:
print(“The “+key+” has not been assigned as yet”)
else:
print(“The “+key+” has been assigned to “+value)
#print value

#Creates an IKHandle
def MakeIKHandle(start,end,name):
cmds.ikHandle( sj=dropdownListdefi[start], ee=dropdownListdefi[end])
cmds.rename(name)

#Creates joints for the reverse foot based on where the original joints of the foot are
def CreateReverseFootJoint(newname,selectIK,rotation,location):
cmds.select( d = True )
cmds.joint ( p=(0, 0, 0) )
cmds.rename(newname)

cmds.select(selectIK)
rotation = cmds.xform(q = 1,rotation = 1)
location = cmds.xform(q = 1,translation = 1)

cmds.select(newname)
cmds.move(location[0],location[1],location[2])

#Uses the two defs from before to create IKHandles and joints based on where the joints are in the scene
def Reverse_Foot(*args):
global dropdownListdefi
global dropdownList

#Used in CreateReverseFootJoint
AnkleRot=0
AnkleLoc=0
BallRot=0
BallLoc=0
ToeRot=0
ToeLoc=0

MakeIKHandle(‘Leg_Joint’, ‘Ankle_Joint’, ‘Ankle_IK’)
MakeIKHandle(‘Ankle_Joint’,’Ball_Joint’,’Ball_IK’)
MakeIKHandle(‘Ball_Joint’,’Toe_Joint’,’Toe_IK’)

CreateReverseFootJoint(‘ReverseFoot_Ankle’,’Ankle_IK’,AnkleRot,AnkleLoc)
CreateReverseFootJoint(‘ReverseFoot_Ball’,’Ball_IK’,BallRot,BallLoc)
CreateReverseFootJoint(‘ReverseFoot_Toe’,’Toe_IK’,ToeRot,ToeLoc)

#Creates a Heel joint using the X and Z coordinates of the Ankle and the Y coordinates of the Toe
cmds.select( d = True )
cmds.joint ( p=(0, 0, 0) )
cmds.rename(‘ReverseFoot_Heel’)
cmds.select(‘Ankle_IK’)
HeelLocXZ = cmds.xform(q = 1,translation = 1)
cmds.select(‘Toe_IK’)
HeelLocY = cmds.xform(q = 1,translation = 1)
cmds.select(‘ReverseFoot_Heel’)
cmds.move(HeelLocXZ[0],HeelLocY[1],HeelLocXZ[2])

#Connecting the joints for the ReverseFoot
cmds.connectJoint(‘ReverseFoot_Toe’, ‘ReverseFoot_Heel’, pm=True )
cmds.connectJoint(‘ReverseFoot_Ball’, ‘ReverseFoot_Toe’, pm=True )
cmds.connectJoint(‘ReverseFoot_Ankle’, ‘ReverseFoot_Ball’, pm=True )

#Parenting ikhandle to ReverseFoot
cmds.parent( ‘Ankle_IK’, ‘ReverseFoot_Ankle’, )
cmds.parent( ‘Ball_IK’, ‘ReverseFoot_Ball’, )
cmds.parent( ‘Toe_IK’, ‘ReverseFoot_Toe’, )

#Creating the menu
def BuildUI(*args):

if cmds.window(“Reverse Foot Tool”, exists=True):
cmds.deleteUI(“Reverse Foot Tool”, window=True)
window = cmds.window( title=”Reverse Foot Tool”, widthHeight=(350, 400), sizeable=(False), maximizeButton=(False) )
cmds.rowColumnLayout(numberOfColumns=1, columnWidth=[(1,335)], rowSpacing = [(1,10)], columnSpacing = [(1,5)])
cmds.text(align = “center”, font = “boldLabelFont”, ww = True, label = “Choose the joint you want to select from the drop down menu, select the joint in maya, then click ‘Select the joint'”, h=40)
cmds.optionMenu( label=’Joints’, changeCommand=StoreSelectedControl )
global dropdownListdefi
global Selected
for key in dropdownListdefi:
cmds.menuItem( label = key)
cmds.button( label=’Select the Joint’,command=SelectJoint)
cmds.rowColumnLayout(numberOfColumns=1, columnWidth=[(1,335)], rowSpacing = [(1,10)])
cmds.button( label=’Check if all the items are selected’,command=CheckingIfSelected)
cmds.text(ww = True, label = “Check the script editor to see what’s been selected”)
cmds.rowColumnLayout(numberOfColumns=1, columnWidth=[(1,335)], rowSpacing = [(1,20)])
cmds.button( label=’Make the reverse foot’,command=Reverse_Foot, h=100)
cmds.rowColumnLayout(numberOfColumns=1, columnWidth=[(1,170)], rowSpacing = [(1,10)], columnSpacing = [(1,84)])
cmds.button( align = “center”, label=’Close’, command=(‘cmds.deleteUI(\”‘ + window + ‘\”, window=True)’) )
cmds.text(“Made By Emma Roseburgh”)
cmds.showWindow( window )

BuildUI()