Hi everybody,
I am new to python and scripting in general, and trying hard to make sense of it. A little background about this particular issue I am having :
I am rigging a bird, and for the feathers my approach is to point constrain them to the arm joints then orient constrain them to three controllers, one at the shoulder, the second one at the elbow and the last one at the wrist.
I would like the feathers in between two of these controllers to be affected by both, proportionally to the distance from them - the math poses no problem. The problem arises when I try to enter a variable name (which is the normalized distance value for this particular feather) into the weight parameter of the orientConstraint command - Maya says it wants only floats. Is there a way I can do this ?
Same issue for the actual names of the objects I want to constrain/be constrained : only strings are accepted and I would like to insert a variable in there (obj1, obj2âŚ).
For reference, this is the current state of my code. It is most likely very ugly, please bear with me.
import maya.cmds as cmds
pos0 = [0, 0, 0];
pos1 = [0, 0, 0];
pos2 = [0, 0, 0];
dist1 = 0;
dist2 = 0;
# finding world space position of objects
pos0[0, 1, 2] = cmds.xform('obj0',q=1,ws=1,rp=1);
pos1[0, 1, 2] = cmds.xform('obj1',q=1,ws=1,rp=1);
pos2[0, 1, 2] = cmds.xform('obj2',q=1,ws=1,rp=1);
def get_dist(base, tip):
# vector substract hack I found on stackexchange
[m - n for m, n in zip(pos2, pos1)]
def get_normalized_dist(dist1, dist2):
1/(dist1+dist2)
return normalized_dist
sel = cmds.ls(selection=True)
for obj in sel:
cmds.pointConstraint( 'obj1', 'obj0', w='weight1' )
My second problem is : how to feed the returned values of the xform command into my lists (pos0[], pos1[] and pos2[]) ? Right now Maya returns an error saying âlist indices must be integers, not tuplesâ.
I hope my english was understandable. Itâs not easy to explain. Could anyone please help ?
Hadrien
