PDA

View Full Version : about the dynamic name in Expressions loop


grayorange
03-14-2009, 12:01 PM
I have 10 boxes. named box1~10.
and created a attr "boxesRotate" in object "control".

I writed this in Expressions editor:
--------------------------------------------
$i;
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:

ronviers
03-14-2009, 05: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.

grayorange
03-14-2009, 06: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.

actually...
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!

ronviers
03-14-2009, 10: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.

http://www.youtube.com/watch?v=CFOCHhtMzXU

Good luck,
Ron

HapG
03-19-2009, 05: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;
$i;
for($i=1; $i<11; $i++) {
$exp += ("box" + $n + ".rotate = control.boxesRotate * "+$i+" * 0.5;");
}
expression -s $exp;

CGTalk Moderation
03-19-2009, 05: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.