When you have an error, itâs pretty essential to post the error. Otherwise we are guessing.
But I guess the problem is that you are using cmds.aliasAttr() and that returns more than just the blendshape targets. So youâre trying to connect something wrong in the loop.
I honestly have no idea how to do this in maya.cmds. I use PyMEL to iterate over pm.PyNode('blendShape1').weight
which does only return the indices. But that is derived from a Maya API function.
In Maya.cmds, the only other thing I can think off off-hand is cmds.blendShape('blendShape1', weight=True, q=1)
which will list the VALUE of each weight. But at least you get the correct number of weights. And you could use that in your range iterator to get the correct number, at least.
But depending on corrective shapes, or if you delete a weight, and add another, the index order will get messed up. So this can still fail. Which is why I like the PyMEL version. It returns the proper index of each target and gives you the plug to connect to, directly.
For example, after I deleted some random targets and added new ones, I get this, out of order:
for each in pm.PyNode('blendShape1').weight:
print(each)
# RESULT:
blendShape1.weight[0]
blendShape1.weight[2]
blendShape1.weight[3]
blendShape1.weight[4]
blendShape1.weight[6]
blendShape1.weight[7]
blendShape1.weight[8]
Alternatively, since cmds.aliasAttr('blendShape1', q=1)
seems to return a list of [target, weight, target, weight, target, weight]
, you could also just iterate over every 2nd element in that list, and maybe youâll get the correct result (I have no idea!):
for each in right_LIST:
print(each)
// RESULT:
pSphere2
weight[0]
pSphere4
weight[2]
pSphere5
weight[3]
pSphere6
weight[4]
pSphere8
weight[6]
pSphere9
weight[7]
pSphere10
weight[8]
So instead, skip every 2nd one. This notation is called âindex slicingâ in Python.
for each in right_LIST[1::2]:
print(each)
// RESULT:
weight[0]
weight[2]
weight[3]
weight[4]
weight[6]
weight[7]
weight[8]
And lastly (sorry for the huge long reply), you donât need to use a range to iterate over things in Python. Iterate over them directly when possible.
And you can combine two lists together by using zip(). For example:
for eachLeft, eachRight in zip(left_LIST, right_LIST[1::2]):
cmds.connectAttr("null1." + eachLeft, "blendshape1." + eachRight)