View Full Version : Operations on multiple objects with For()

03 March 2009, 09:53 PM
I have a set of objects named similarly, eg. pPlane1, pPlane2, pPlane3, etc. and I have them set up to scale based on their position along a corresponding motionPath.
Currently each object has it's own expression similar to the following;

pPlane1.scaleY = sin(3.14*(motionPath1.uValue));
pPlane1.scaleZ = pPlane1.scaleY;

I want to combine all the scripts into one for() statement in order to make changing things a lot easier. The problem is I cannot find the proper syntax for using a variable in an object name. To give you an idea of what I'm doing, here is my incorrect syntax attempt;

int $i;
for ($i = 1; $i < 25; $i++) {
pPlane($i).scaleY = sin(3.14*(motionPath($i).uValue));
pPlane($i).scaleZ = pPlane($i).scaleY;

Anyone care to shed some light on the correct way to do this?

03 March 2009, 11:49 PM

Try this. It's experimental, so there may be problems!

int $i;
for ($i = 1; $i < 25; $i++) {

float $uValue = getAttr ("motionPath" + $i + ".uValue");
setAttr ("pPlane" + $i + ".scaleY") (sin(3.14 * $uValue));
setAttr ("pPlane" + $i + ".scaleZ") (sin(3.14 * $uValue));

Good luck!


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