PDA

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


UberSprode
03-17-2009, 10: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?

mlefevre
03-18-2009, 12:49 AM
Hey,

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!

-matt

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