View Full Version : about the dynamic name in Expressions loop

03 March 2009, 11:01 AM
I have 10 boxes. named box1~10.
and created a attr "boxesRotate" in object "control".

I writed this in Expressions editor:
for($i=1; $i<11; $i++) {
("box" + $n + ".rotate") = control.boxesRotate * $i * 0.5;
but // Error: Syntax error //

I know the problem is in --->("box" + $n + ".rotate")
so, how to write the dynamic name in loop?:shrug:

03 March 2009, 04:32 PM
float $rB=0;
int $i=0;
for($i=1; $i<11; $i++) {
$rB =`getAttr control.rotateBoxes`;
setAttr ("box" + $i + ".rotateY") $rB;

Not 100% sure what you are trying to do, but maybe this will get you closer.

03 March 2009, 05:40 PM
Oh~ very thanks!
I've use that before.
but if I writed "setAttr"
than it should click the play button to see the effect.
it can't appear in real time.

I'm trying to make a spiral joint animation.
I made the joints line up.
If I set the rotate to each of them. they will become a circle.
not a spiral shape.
so I want to make each of the rotate value a little more than last.

but still very thank you! :) really!

03 March 2009, 09:40 PM
Here is something I found on youtube. I do not think this is what you have in mind, but it may be easier if you work through a tutorial first as a way to better understand how to break down your project and ask more targeted questions.

Good luck,

03 March 2009, 04:24 PM
If you want the expression to evaluate properly, you have to stay away from getAttr/setAttr

you have the right idea with ("box" + $n + ".rotate"), but you should just write the expression with full names. You can use a script to "write" the expression for you.

string $exp;
for($i=1; $i<11; $i++) {
$exp += ("box" + $n + ".rotate = control.boxesRotate * "+$i+" * 0.5;");
expression -s $exp;

CGTalk Moderation
03 March 2009, 04:24 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.