PDA

View Full Version : Illegal Attribute in Expression...cannot find why


Phlok
05-12-2009, 04:00 PM
I wrote a script that dynamically creates expressions, unfortunately I always get a

Error: Illegal attribute in expression: GObject10

message. I have been trying things for hours, now but I can't figure out what's going wrong there- maybe you can help.

Here's the code. The first three strings are for debugging, GObject10 is a group, containing objects and it is connected to a shader named "SShadeGObject10"


string $item = "GObject10";
string $grp = "GObject10";
string $aux = "\"SShade\"";

string $content =
"int $moCheck; \r\n"+
"$moCheck = `getAttr " + $item + ".translateX" + " ` ; \r\n"+
"int $iter; \r\n"+
"if($moCheck != 0)"+
"{ \r\n"+
"$iter = `getAttr " + $item + ".iterations" + " ` ; \r\n"+
"enlightenIt(" + $item +" ); \r\n"+
"$iter += $iter; \r\n" +
"setAttr " + $item + ".iterations " + " $iter;"+
"}\r\n" +

"if($iter == 10)"+
"{ \r\n" +
" expression -s \" \" $item; \r\n" +
"} \r\n" +


"proc enlightenIt(string $grp){ \r\n"+
"string $mat = (" + $aux + "+ $grp); \r\n"+
"vector $col = `getAttr ($mat + \".outColor\")` ; \r\n" +
"vector $col1 = <<$col.x + 0.1, $col.y + 0.1, $col.z + 0.1>>; \r\n" +
"setAttr ($mat + \".outColor\") ($col1.x) ($col1.y) ($col1.z); \r\n"+
"}";

expression -s $content $item;


I can do all the "getAttr GObject10.outColor" or setAttr GObject10.outColor 1 1 1 via single commands in my scene and everything's working fine.

If I just type a "cleaned" non- dynamically created version of the script into the script editor, everything is running just fine:

int $moCheck;
$moCheck = `getAttr ($item + ".translateX") `;
int $iter;
if($moCheck != 0)
{
$iter = `getAttr ($item + ".iterations")`;
enlightenIt($item);
$iter += $iter;
setAttr ($item + ".iterations") $iter;
}

if($iter == 10)
{
expression -s "" $item;
}

proc enlightenIt(string $grp)
{
string $mat = (" + $aux + "+ $grp);
vector $col = `getAttr ($mat + ".outColor")`;
vector $col1 = <<$col.x + 0.1, $col.y + 0.1, $col.z + 0.1>>;
setAttr ($mat + ".outColor") ($col1.x) ($col1.y) ($col1.z);
};


I really do not see the cause for this error, so please help if you can!

isoparmB
05-13-2009, 03:41 AM
Would you be able to tell us exactly how the script operates and what it does? I need to know what your intention is before I can troubleshoot.

From the looks of your script, it generates an empty expression if the iterations on a certain object reach ten, but the condition looks dangerous because you are adding iterations to each other instead of just adding + 1, which will cause your condition to overshoot if the result is not exaclty ten. I'm not sure if this is what you prefer though. I think it should be >= 10, but again I don't know the intentions of your script. And also, I think it should be $iter ++; instead of $iter += $iter also, but again I don't know the specific logic you are trying to achieve.

I was able to recreate and idea of the conditions your script operates on, an sphere parented under GObject10 group with an int iterations attribute, and a surface shader assigned to the sphere. If the translate is != 0, then the surface shader receives the .1 in value, so I guess it starts out black and reaches white when it reaches 10 iterations.

Were you planning on creating the empty expression and then later editing it to incorporate the procedure so that the objects in the GObject10 group would update from black to white within ten frames?

Phlok
05-14-2009, 10:18 AM
Thanks for the help!

Adding the iterations to oneanother wasn't the intended way of doing things. In the final version, I added just 1 (BTW I think its still annoying ++ don't work for iterating by one in MEL).

The problem was caused when creating the expression. GObject40 was passed as an argument without the "" so Maya was confused and couldn't work with it.

CGTalk Moderation
05-14-2009, 10:18 AM
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.