PDA

View Full Version : using variable as Attr


defago
10-29-2006, 10:22 PM
Im finally getting around to learning mel, and im running into one very obnoxious problem.
If i want to use a string in my procedure to add an attribute, how do I call on that attribut later in the script?

for example if I do

proc control (string $newAttr)
{
addAttr -ln $newAttr -at "float" -k 1 -w 1 -min 0 -max -0 -dv 1 controller;
setAttr controller.$newAttr 10;
}

I get a syntax error.

// Error: setAttr controller.$newAttr 10;


Obviously maya doesnt like me using a variable for an attribute; any help is greatly appreciated.

Thanks

BlackHwk4
10-29-2006, 10:32 PM
Try this:

proc control (string $newAttr)
{
addAttr -ln $newAttr -at "float" -k 1 -w 1 -min 0 -max 10 -dv 1 controller;
setAttr ("controller." + $newAttr) 10;
}

defago
10-29-2006, 11:18 PM
Thanks blackhwk, exactly what i needed. now- i guess i have to start scripting again

CGTalk Moderation
10-29-2006, 11:18 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.