Aikiman
07-12-2008, 07:11 AM
I wanna get this sorted once and for all because Im tearing my hair out here everytime I come across this same issue, somebody please shed some light on this and Ill be eternally grateful. Heres the problem....I need to know what is the best way to incorporate a string variable from a list selection command into a dynExpression. Example below.
global proc jrSpriteAim()
{
// get shape node from selection
pickWalk -d down;
string $particle[] = `ls -sl`;
// add particle attribute to shape
addAttr -ln spriteTwistPP -dt doubleArray $particle;
addAttr -ln spriteTwistPP0 -dt doubleArray $particle;
// write string the expression
string $exp =
("float $angle = angle(particleShape1.velocity, <<0,1,0>>);\n" +
"float $deg = rad_to_deg ($angle);\n" +
"vector $vel = velocity;\n" +
"float $blend = (smoothstep (-.5, .5, $vel.z)*2)-1;\n" +
"particleShape1.spriteTwistPP = $deg*$blend;\n" );
dynExpression - rbd -s $exp $particle;
}
Now, I want to be able to replace the red code with the green variable code. The problem boils down to syntax. As far as I see it if $particle was hard coded into the particle expression it wont work because it then becomes undeclared, therefore the expression needs to evaluate before it is written to the particle so that $particle becomes particleShape1 in the expression, am I right here? Also the runtime expression doesnt need extra quotes or brackets so these must be used and evaluated before the dynExpression is called. Ive tried every combination under the sun (except the right one) but I just cant see a pattern where it will work. Is this situation better suited for the eval command instead?
Please somebody put me out of my misery.
global proc jrSpriteAim()
{
// get shape node from selection
pickWalk -d down;
string $particle[] = `ls -sl`;
// add particle attribute to shape
addAttr -ln spriteTwistPP -dt doubleArray $particle;
addAttr -ln spriteTwistPP0 -dt doubleArray $particle;
// write string the expression
string $exp =
("float $angle = angle(particleShape1.velocity, <<0,1,0>>);\n" +
"float $deg = rad_to_deg ($angle);\n" +
"vector $vel = velocity;\n" +
"float $blend = (smoothstep (-.5, .5, $vel.z)*2)-1;\n" +
"particleShape1.spriteTwistPP = $deg*$blend;\n" );
dynExpression - rbd -s $exp $particle;
}
Now, I want to be able to replace the red code with the green variable code. The problem boils down to syntax. As far as I see it if $particle was hard coded into the particle expression it wont work because it then becomes undeclared, therefore the expression needs to evaluate before it is written to the particle so that $particle becomes particleShape1 in the expression, am I right here? Also the runtime expression doesnt need extra quotes or brackets so these must be used and evaluated before the dynExpression is called. Ive tried every combination under the sun (except the right one) but I just cant see a pattern where it will work. Is this situation better suited for the eval command instead?
Please somebody put me out of my misery.
