FORUMS: list search recent posts

new to Mel - array question?

COW Forums : Autodesk Maya

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
raina-bab
new to Mel - array question?
on Sep 16, 2007 at 12:16:37 pm

Hi,

i am learning mel, i have been through the help files but still cant get my head around array.

I have a square, and want to copy it at regular intervals. How would I define a MEL script to do this? I tend to learn a lot from working examples so your help is greatly apreciated!

thanks



Return to posts index

Sean Fennell
Re: new to Mel - array question?
on Sep 18, 2007 at 4:08:06 pm

An array is just a variable that holds a list of values. For your purposes it sounds like you want a loop, in addition to an array.

Use the array to store the names of the copied objects. Use the for loop to copy them at regular intervals. Lets say the interval is every frame for 15 frames. Here's an example:


string $copiedObjects[];
int $currentTime = `currentTime -query`;
int $maxTime = $currentTime + 15;
// store this so its easy to get the original selection back
string $selection[] = `ls -sl`;

for(int $i = $currentTime; $i <= $maxTime; $i++)
{
// select the original selection
// (this way we dont duplicate the duplicates)
select -r $selection;
// step one frame forward in time every time the loop runs
currentTime -edit $i;
// duplicate the object
string $copy[] = `duplicate -rr`;
// the duplicate command returns an array of the duplicate objects
// assuming we only have one object selected, assign the first
// value of the $copy array to the index of the $copiedObjects
// array that matches this loop (the value $i is the index for this
// loop
$copiedObjects[i] = $copy[0];
}



Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]