PDA

View Full Version : for loop expression query


dr_bob
06-10-2002, 12:51 PM
Hi

I want the movement of a locator to control the rotation of a number of cylinders, numbered cyl1, cyl2 ,cyl3 and so on. I have no problem writing a basic expression to facilitate this, with a new line in the expression for each cylinder, but it doesn't seem very elegant.

Is there any way to set up a for loop or while loop, using an int to change the name of the cylinder in the loop?

Thanks in advance.

svenip
06-10-2002, 12:57 PM
for($i=0;$i<=10;$i++)
{
$cmd = "cylinder_"+$i+".rotateX = locator1.translateX;";
eval $cmd;
}

now you need only 10 cylinders named correctly (cylinder_1,cylinder_2....)

and if you want a slight difference the maybe this one

for($i=0;$i<=10;$i++)
{
$cmd = "cylinder_"+$i+".rotateX = locator1.translateX + "+$i*10+";";
eval $cmd;
}

now the seconde one (cylinder_1) gets 10 degrees more and so on

dr_bob
06-10-2002, 01:16 PM
That's great - thanks for the quick reply :-)

CGTalk Moderation
01-13-2006, 08: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.