View Full Version : add Attribute using a loop
johnjoe 11-06-2008, 10:25 AM Hi, I'm having problems adding attributes using a loop. Would someone take a quick look at what I've got? Massive thanks :bowdown:
string $animControl[] = "curve1_ctrl";
int $num_of_balls = 8;
for ($i =0; $i<$num_of_balls; $i++){
string $ctrlAt = ("ctrl_"+ ($i +1));
addAttr -ln $ctrlAt -at double -min 0 -max 10 -dv 10 $animControl;
setAttr -e-keyable true ($animControl[0] +" .$ctrlAt");
}
the addAttr part is working just NOT the setAttr . :lightbulb
big thanks in advance :rolleyes:
|
|
NaughtyNathan
11-06-2008, 10:35 AM
string $animControl[] = "curve1_ctrl";
setAttr -e-keyable true ($animControl[0] +" .$ctrlAt");
putting [] after a variable name declares it as an array. You cannot assign a single string as an array like this. What are you trying to do? should $animControl be an array? or a single string?
also, you've put a variable INSIDE a literal string: ($animControl[0] +" .$ctrlAt") should be:
($animControl[0] + "." + $ctrlAt);
variables shouldn't ever be inside quotes (unless you're doing really clever/complex code), and finally, don't put spaces inside your object/attribute concatenations (" ." above)
// array method:
string $animControl[] = { "curve1_ctrl" };
setAttr -e-keyable true ($animControl[0] + "." + $ctrlAt);
is fine, or:
// single string method:
string $animControl = "curve1_ctrl";
setAttr -e-keyable true ($animControl + "." + $ctrlAt);
but not what you've got.
:nathaN
johnjoe
11-06-2008, 10:48 AM
Worked Like a dream :thumbsup: I'm slowly beginning to understand the way in which MEL is written. Thanks for all your great help
Regards
Joe :beer:
CGTalk Moderation
11-06-2008, 10:48 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.
vBulletin v3.0.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.