PDA

View Full Version : Simple for loop ?


Aikiman
01-17-2007, 08:52 PM
This seems to be a pretty simple mel question but Im hopeless with mel and tried to figure it but got stuck.

I have for example 500 pCube called pCube1 - 500.
They are all active rigids and want to connect a gravity field to them all. For some reason Maya doesn't let me select all the rigids then go to the menu and apply gravity, it looks as though I can only do it through the dynamics relationship editor one by one, ha ha ha, or use mel.
I know this is the mel to connect gravity to one cube...

connectDynamic -f gravityField1 pCube1;

and that I should use a for loop and an array but thats about it, anybody?

Sanctuary
01-17-2007, 09:36 PM
simpliest way


for ($i=1; $i<=500; $i++)
{
connectDynamic -f gravityField1 ("pCube" + $i);
}

Aikiman
01-17-2007, 10:33 PM
thanks dude, just about got there myself.

TAKADS
01-18-2007, 08:55 AM
Hey Aikiman,

Glad you solved it with this code, but i don't understand what the problem was to start with.
Select all 500 cubes, then go to Fields Gravity. All cubes will be made Rigid Bodies and have the gravity field applied to them. It also works if u already have the cubes as rigid bodies.
If you have the cubes and an existing field (gravity for ex), select all cubes then the field (last) then go to field>affect selected objects.

Works every time, but hey no harm in learning some mel either :D

Aikiman
01-19-2007, 04:35 AM
TAKADS,
In theory (and practice) this should work but I think it must be a bug in the Mac version, hence the hard coding.

CGTalk Moderation
01-19-2007, 04:35 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.