Constructing a statement with vertex index changin

I am making a custom morph between two target shapes by making the vertex position of my base shape equal to the average of two target shapes' vertexes on a one to one basis.

the problem is that when I make a loop, I get a syntax error when I plug the variable $counter into the place where the vertex index needs to be.

here is how the statement by itself looks (this version works):

baseShape.pnts[2].pntx = (((targetAShape.pnts[2].pntx *100) + (targetBShape.pnts[2].pntx *100)) / 200);

however when I make a loop to do all of the vertexes, there is an error:

int $counter = 1;
while ($counter < 6)
{
$counter = ($counter + 1);
baseShape.pnts[$counter].pntx = (((targetAShape.pnts[2].pntx *100) + (targetBShape.pnts[2].pntx *100)) / 200);
}

does anyone know why this is?

When working with numbered verts like that, the name of the vertex is treated as a string. So just plugging in a variable between the brackets doesn't work. You need to build it up as a string.

Now onto the syntax of your equals statement. Attribute vallues cannot be simply set by assigning a value through equality like you would with a variable.

So lets give this a shot...

int $counter = 1; //This set up to go from 2 through 5, that seems a bit odd...
while ($counter < 6)
{
$counter = ($counter + 1);

//Build the name of the vertex string
string $vertexPntxName = ("baseShape.pnts[" + $counter + "].pntx");

//Retrieve the attr values we need
float $targetAShapeValue = getAttr targetAShape.pnts[2].pntx;
float $targetBShapeValue = getAttr targetBShape.pnts[2].pntx;
float $valueToAssign = ($targetAShapeValue *100) + ($targetBShapeValue *100) / 200); //btw, *100 /200 is the same as *0.5

//Set attribute value
setAttr $vertexPntxName $valueToAssign;
}

I think that is correct, anyway. I don't work much with morph target so I am not used to dealing with the pntx stuff.

Actually now that I look at it it seems that you original attempt looks a lot like an expression, so maybe this is all completely worthless to you Oh well.

--JeffD

thanks for the help! it didn't work but it led me to what did...

aparently you have to do something like this...

int $i;
int $numA;
int $numB;
int $numC;
for ($i=0; $i < 5; $i++)
{
$count = $i;
$numA = `getAttr targetAShape.pnts[$count].pntx`;
$numB = `getAttr targetBShape.pnts[$count].pntx`;
$numC = ($numA + $numB)/2;
string $command = "setAttr "baseShape.pnts["+$count+"].pntx"" + $numC;
eval ($command);
print $numA; print "n"; print $numB; print "n"; print $numC; print "n"; print $i;
print $command;
}
//setAttr "baseShape.pnts[0].pntx" $numC;
//baseShape.pnts[2].pntx = 1;

isnt this a bit painfully slow... using expressions with direct connections should give you much faster perfroemance! And not using getattr in them at all!