Search code examples
selectduplicatesmayamelcurrent-time

Maya (MEL) duplicate selected object at specific time interval


I have an object (Cube for example) that is keyed to move (Translate) from point A to point B in 20 frames. At frame 1 (currentTime 1) the objects is at point A and at frame 20 (currentTime 20) the object moves to point B.

What I want to achieve is to want to make a duplicate of the main object at specific time intervals, let's say 5,10 and 15 for example.

I made a simple code that worked for my object (named "Konga"), here it is.

select -r Konga ;
currentTime 1 ;
duplicate -rr;
select -r Konga ;
currentTime 5 ;
duplicate -rr;
select -r Konga ;
currentTime 10 ;
duplicate -rr;
select -r Konga ;
currentTime 15 ;
duplicate -rr;

But now I want it to modify the code to make it work with 'any' object I select

So I made a modification to the code based on information I found on another post on how to apply code to selected objects

string $sel[] = `ls -sl`;
string $obj;
for ($obj in $sel)
{
  currentTime 5 ;
  duplicate -rr;
  currentTime 10 ;
  duplicate -rr;
  currentTime 15 ;
  duplicate -rr;
}

But all this code does is make duplicate of the selected objects at the first mentioned currentTime which happens to be 5 here. So I end up with 3 duplicates of the main object, all at the same location of where the main object was at time 5 and nothing at 10 and 15. What did I do wrong here, should I have selected the object multiple times like in the previous code?

I'm just a 3d modeler and not really into scripting so please help me out.


Solution

  • Your problem is that you do not tell the duplicate command exactly what to duplicate. By default it just uses the currently selected objects what seems not to be what you want. But you can give it the name of the object you want to duplicate like this:

    string $sel[] = `ls -sl`;
    string $obj;
    for ($obj in $sel)
    {
      currentTime 5 ;
      duplicate -rr $obj;
      currentTime 10 ;
      duplicate -rr $obj;
      currentTime 15 ;
      duplicate -rr $obj;
    }