PDA

View Full Version : Aaaaahhh! More string problems!


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.

GiantG
07-12-2008, 09:41 AM
The easyiest Way of doing this string stuff is to let maya do it for you.

First write your stuff clean and put it in the Expression Editor.

float $angle = angle(($particle + ".velocity"), <<0,1,0>>);
float $deg = rad_to_deg ($angle);
vector $vel = velocity;
float $blend = (smoothstep (-.5, .5, $vel.z)*2)-1;
setAttr ($particle + ".spriteTwistPP) = $deg*$blend;

Change the particleshape parts to $particle and try to remember the syntax for it.

command($variable + ".attribute");

then press create inside the EE and go to the script editor.
Copy out the part after the -s flag and paste it after your dynExpression - rbd -s

so you have

dynExpression - rbd -s "float $angle = angle(($particle + \".velocity\"), <<0,1,0>>);\r\nfloat $deg = rad_to_deg ($angle);\r\nvector $vel = velocity;\r\nfloat $blend = (smoothstep (-.5, .5, $vel.z)*2)-1;\r\nsetAttr ($particle + \".spriteTwistPP) = $deg*$blend;\r" -o "" -n "MyName" -ae 1 -uc all ;

You don't have to concatenate the string.
Maybe dynExpression has some other spezial flags that you have to clean out...

CHeerz...

tbaypaul
07-12-2008, 03:53 PM
gosh, you were so close.....I think you gave up 2 minutes too soon...



global proc jrSpriteAim()
{
pickWalk -d down;
string $particle[] = `ls -sl`;
addAttr -ln spriteTwistPP -dt doubleArray $particle;
addAttr -ln spriteTwistPP0 -dt doubleArray $particle;
string $exp =
("float $angle = angle(" + $particle[0] + ".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" +
$particle[0] + ".spriteTwistPP = $deg*$blend;\n" );
dynExpression - rbd -s $exp $particle;
}

Aikiman
07-12-2008, 11:11 PM
thanks for your help guys...

gosh, you were so close.....I think you gave up 2 minutes too soon...

oh that worked! thankyou I think I got it now. The variable goes outside the quotes, no extra brackets or quotes, geez I hope this is the end of my troubles here once and for all. Thanks again guys for your time and help....big thumbs up!

CGTalk Moderation
07-12-2008, 11:11 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.