PDA

View Full Version : EXpreSSION quEstioN


EdmX
02-06-2004, 02:33 PM
:surprised
Hi people,
Im trying to make an expression, but im not so good on it.
I wouyld like to know if someone could help me.
I need to move a bunch of objects at same time, same animation.

example:
Ive a box wich I want to rotate on X..and Ive more 20 boxes called box1, box2, box3, etc...wich I want to be driven by the Box Master..

the expression is this one..

box1.rotateX=Mainbox.rotateX;

but this expression only moves the box1.. My question is, if have a way to type this expression...like

box#`.rotateX=Mainbox.rotateX

and the other boxes move..i dont need to type individuals expressions..

pleaseeeeeeeeeeeeeee
help meeeeeeeeeeeeeeeeeeee

tanx

alesmav
02-06-2004, 02:59 PM
why don't you use connection editor instead?
ALES

EdmX
02-06-2004, 03:43 PM
i migth do that..
but i was trying to figure out if with expression could be better..
:beer:

jHromika
02-06-2004, 06:46 PM
one way would be to wrtite a snippet of code where you loop through writing the expression 20, or however many times is needed.



for ($i = 1; $i <= 20; $i++)
expression -s ("box" + $i + ".rotateX = mainBox.rotateX");




Just a basic for loop. The counter, $i, starts at 1 and as long as $i is less than or equal to 20 (or however many boxes you need to add the expression to) it will add an expression to each box. After the expression is written to box$i, $i increases by one ($i++) and as long as $i is still less than or equal to 20, it does it again.

For that code though, they need to be named box1, box2, box3, etc. If you wanted to do it with a selection, you'd have to modify the code a bit.

That code can either be placed within the expression editor, or it could be placed in the script editor and executed with the numPad enter.

Of course, as alesmav said, since you're just making a straight connection, the connection editor might be better. But never fear! You can loop that too!!



for ($i = 1; $i <= 20; $i++)
connectAttr mainBox.rotateX ("box" + $i + ".rotateX");



Again with the above loop, you could place it in the expression editor if you want, or you could just run it once from the script editor.

Good luck :thumbsup:

The Time Serpent
02-07-2004, 08:06 AM
oooo a loopin solution :bounce:
i might finally finish my script :scream:
Henrique BiG ThAnKs FoR CrEaTiN ThAt ThReAd :beer:

jHromika thanks for clearin up the loopin thing :beer:

alesmav
02-07-2004, 07:10 PM
... or you can just select the objects you want to connect and run the following script.

-------------------------------------------------

string $sel[0] = `ls -sl`;

for ($i = 1; $i < size ($sel); $i++)
connectAttr ($sel[0] + ".rotateX") ($sel[$i] + ".rotateX");

---------------------------------------------------------------------------

Be sure to select the "master" object first.

ALES

The Time Serpent
02-07-2004, 11:43 PM
is it possible to create a chain of variables this way? (i mean the above )
like when i first time use the script the all the variables have number 1 in their names and when i use the script the second time they get number 2 in the names?

brubin
02-24-2004, 10:39 AM
you can also do this in ONE expression:

box20.tx=box19.tx= [...] masterbox.tx ;

where you should continue where the [...] is, next same for ty, tz
or whatever else. (actually it should've been rotate[?] never mind you get the point)

HIH
s.

EdmX
03-15-2004, 02:15 PM
:buttrock:

hey guys..tanx very much for the answers...
the movie i was making went down...
:surprised

but tanx a lot for all....


cheers

CGTalk Moderation
01-17-2006, 09:00 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.