Hi, I am fairly new to python coding, and after following a number of tutorials I wanted to make some Auto rig tools to speed up the making of a uni rigg I have.
for now, I am only trying to automate the low part of the rig e.g legs in order to get my head around the code however I am coming across a problem when trying to parent constraint joints to locators and making there higher arches
so the basis of the tool is to create a number of proxy locators then position them in the world and then create a joint hierarchy base on their position. Unfortunately, I am stuck at the joints
Here is the code I am using for the locators and this works fine
def create_Loc():
amount = 6
for i in range(amount):
count = i+1
loc = cmds.spaceLocator (n = 'locator_{}_PRX'.format (count), p = [0,i*2.5,0])
cmds.makeIdentity (loc, a = 1, t = 1)
mel.eval ('CenterPivot;')
cmds.select ('*_PRX')
lyr = cmds.createDisplayLayer (n = 'locators', num = 1)
cmds.setAttr ('locators.color', 22)
however, when going on to create the joints I would like them to be based on the locator’s positioning with specific naming conventions here is the code I have right now witch takes the names of a list using a for loop and creates the joint for each name in the list
# Make joints
names = ['C_Pelvis_jnt','l_leg_jnt','l_knee_jnt','l_ankle_jnt','l_toe_jnt','l_foot_ball_jnt']
for name in names:
cmds.select (cl = 1)
jnt = cmds.joint (n = name , sc = 0 )
however, I am struggling with the next part of the code which is to parent constraint each joint to the right locator I have tried to use something within the lines of
# Constrain joints to Locators
Loc = cmds.ls ('*_PRX')
if Loc:
con1 = cmds.parentConstraint(Loc[0],names[5])
con2 = cmds.parentConstraint(Loc[1],names[4])
con3 = cmds.parentConstraint(Loc[2],names[3])
con4 = cmds.parentConstraint(Loc[3],names[2])
con5 = cmds.parentConstraint(Loc[4],names[1])
con6 = cmds.parentConstraint(Loc[5],names[0])
cmds.delete(con1,con2,con3,con4,con5,con6) #delete Constraints
# create joint hierarchy
cmds.parent (names[1],names[0])
cmds.parent (names[2],names[1])
cmds.parent (names[3],names[2])
cmds.parent (names[4],names[3])
cmds.parent (names[5],names[4])
But I was thinking there must be a way to make this code shorter and more accurate as to which constraints you are deleting. I also tried to use a for loop in order to parent the joints into a hierarchy.
for n in names:
cmds.parent (n)
however, the for loop did not parent them in the order of the list from 0 to 5, so I was wondering if anyone can give me some advice on how to do this better and more compact.