PDA

View Full Version : error in code


Aikiman
05-16-2008, 05:08 AM
string $expression =

("float $pos[] = ($particle[1] + ".position");\n" +
"setAttr ($closest + ".inPosition") $pos[0] $pos[1] $pos[2];\n" +
"vector $normal = `getAttr ($info + ".normal")`;\n" +
"aimVel = $normal;\n");

dynExpression -c -string $expression $particle[1];


The script editor doesnt get passed the 2nd line of code.

$particle[1] is the particleShape1.

ajk48n
05-16-2008, 05:15 AM
I don't have Maya in front of me, so there could be a few problems, but at first glance, you probably need to escape the quotes inside the expression. Try this, and see if it works.

string $expression =

("float $pos[] = ($particle[1] + \".position\");\n" +
"setAttr ($closest + \".inPosition\") $pos[0] $pos[1] $pos[2];\n" +
"vector $normal = `getAttr ($info + \".normal\")`;\n" +
"aimVel = $normal;\n");

Aikiman
05-16-2008, 06:26 AM
Hi ajk,

I think that has fixed one problem now I have another...


// Error: Line 0.45: Cannot cast data of type string to float[]. //

Im assuming it relates to the "float $pos[]..." but the return is a triple float array?!

kojala
05-16-2008, 07:07 AM
try this:

string $expression =
("float $pos[] = (" + $particle[1] + ".position);\n" +
"setAttr -type double3 (" + $closest + ".inPosition) " + $pos[0] + " " + $pos[1] + " " + $pos[2] + ";\n" +
"vector $normal = `getAttr (" + $info + ".normal)`;\n" +
"aimVel = " + $normal + ";\n");

Aikiman
05-16-2008, 08:34 PM
try this:

string $expression =
("float $pos[] = (" + $particle[1] + ".position);\n" +
"setAttr -type double3 (" + $closest + ".inPosition) " + $pos[0] + " " + $pos[1] + " " + $pos[2] + ";\n" +
"vector $normal = `getAttr (" + $info + ".normal)`;\n" +
"aimVel = " + $normal + ";\n");

// Error: Line 3.66: "$pos" is an undeclared variable. //
// Error: Line 3.82: "$pos" is an undeclared variable. //
// Error: Line 3.98: "$pos" is an undeclared variable. //
// Error: Line 5.23: "$normal" is an undeclared variable. //

which is crap obviously, so it still must be a syntax thing.

ajk48n
05-16-2008, 09:26 PM
I believe $pos and $normal still have to be inside the quotes, since those variables are defined within the expression.

So, something like this


string $expression =
("float $pos[] = (" + $particle[1] + ".position);\n" +
"setAttr -type double3 (" + $closest + ".inPosition) $pos[0] $pos[1] $pos[2];\n" +
"vector $normal = `getAttr (" + $info + ".normal)`;\n" +
"aimVel = $normal;\n");

Aikiman
05-16-2008, 11:07 PM
string $expression =
("float $pos[] = (" + $particle[1] + ".position);\n" +
"setAttr -type double3 (" + $closest + ".inPosition) $pos[0] $pos[1] $pos[2];\n" +
"vector $normal = `getAttr (" + $info + ".normal)`;\n" +
"aimVel = $normal;\n");


okay I tried this and still got errors so I wrote the code out in the expression editor - creation time taking out all the quotes. I thought maybe it was because the $particle/$closest variables etc could not be called from within the particle expression so I also replaced them with the object names themselves ie particleShape1.position etc etc.

Then I still got errors?!

So I took the brackets out that were originally surrounding the $particle, then it worked!
Therefore the following code works, thaks to you guys for your help! Big thumbs up.


string $expression =
("float $pos[] = " + $particle[1] + ".position;\n" +
"setAttr -type double3 " + $closest + ".inPosition $pos[0] $pos[1] $pos[2];\n" +
"vector $normal = `getAttr " + $info + ".normal`;\n" +
"aimVel = $normal;\n");

dynExpression -c -string $expression $particle[1];

CGTalk Moderation
05-16-2008, 11:07 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.