parentConstraint not working

Hello people,

I'm currently going back to scripting in order to earn time on my rigs.
So I tried to make a quick Python rig to place my controlers on selected joints and add a parentConstraint.
Unfortunatly all the constraints appear, are well named, but only the last one is functional.
Any ideas ?

targetJoints = cmds.ls( sl=1 , typ='joint' )

for targetJoint in targetJoints :

    ctrl_name = 'ctrl_' + targetJoint
    ctrl_name = cmds.circle( c=(0, offsetY, 0) , nr=nr , sw=360 , r=radius , ch=False , n= ctrl_name);
    grp_name = 'grp_' + targetJoint

    radius = cmds.getAttr( targetJoint + '.radius' ) * 5
    
    offsetY = 0
    childJoints = cmds.listRelatives( targetJoint , c=1 , typ='joint' )

parent shape

    cmds.group ( n=grp_name, r=True)

    cmds.parent ( grp_name , targetJoint , r=True )

    cmds.parent ( grp_name , w=True , r=False )

constraint

    cmds.parentConstraint ( ctrl_name , targetJoint, mo=1)

Hi, I made a couple of modifications to your script and it worked (or so I think) according to what you are looking for.
Be careful with the '; ', and also do not have if they have the index of the [for] and the [list] called equal.

targetJoints = cmds.ls( sl=1 , typ='joint' )

for target in range(len(targetJoints)) :

ctrl_name = ('ctrl_' + targetJoints[target])
radius = cmds.getAttr( targetJoints[target] + '.radius' ) * 5
offsetY = 0
grp_name = ('grp_' + targetJoints[target])

#WHAT IS NR ??
ctrl_name = cmds.circle( c=(0, offsetY, 0), sw=360 , r=radius , ch=False , n= ctrl_name)

childJoints = cmds.listRelatives( targetJoints[target] , c=1 , typ='joint' )

# Parent

cmds.group ( n=grp_name, r=True)

cmds.parent ( grp_name , targetJoints[target] , r=True )

cmds.parent ( grp_name , w=True , r=False )

# constraint 
cmds.parentConstraint ( ctrl_name , targetJoints[target], mo=1, w=1)

Thank you for your reply Tomas,
I finally found out what was the problem yesterday and it is due to a stupid oversight : my controllers needed to be parented between eachother so their transform could affect the rest of the hierarchy.. So now I'm trying to find out how to do it in python.

About your comment "nr" is the normal of the plane in which the circle will lie, I have different versions depending of the shape I'm using.

Anyway thank you for your modifications. Could you tell me why it would be more interesting to use this format

for target in range(len(targetJoints)) :

Instead of this one ?

for targetJoint in targetJoints :

As it seems to force to use a lot more characters during the script (targetJoints[target] instead of targetJoint)

Hi Jimmy, sure.. I consider myself a beginner in python, but I can always help

You can get the same result.
ex:

targetJoints = ['joint1', 'joint2', 'joint3', 'joint4']
for targetJoint in targetJoints :
print targetJoint

result:
joint1
joint2
joint3
joint4

but with the other for instead
for target in range(len(targetJoints)) :
print targetJoint[print targetJoint]

result:
joint1
joint2
joint3
joint4
if u print the 'target' u obtain the index number of targetJoints:
for target in range(len(targetJoints)) :
print target

result:
0
1
2
3

The good thing is u can use the same 'for' for parent your controls or connect them.
You can create math conditions to make parent between ctrl_name and grp_name orjust another list.

This topic was automatically closed after 87 days. New replies are no longer allowed.