Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Forums Adobe After Effects Expressions Script to Sequence Layers (What i’m doing wrong?)

  • Script to Sequence Layers (What i’m doing wrong?)

  • Vincenzo Imbimbo

    December 29, 2021 at 11:51 am

    Hello guys, i’m trying to create a script to sequence layers, but i’m having this little problem:

    If i have the layers trimmed, they should remain that way, instead they are going back to they original start point, see, if i have layers like the example 1 image, the should be sequenced like the “Good result” image, instead they are sequencing like the “bad result”.

    This is the line of code that i’m using:

    var comp = app.project.activeItem;

    var err = this.selErr;

    if (this.checkActiveItem(comp)) throw(err);

    var selLayers = comp.selectedLayers.reverse();

    if (selLayers.length < 1) throw(err);

    var offset = parseFloat(pal.gr.gr2.framesEt.text) * comp.frameDuration;


    app.beginUndoGroup(this.scriptTitle);

    for (var i = 0; i < selLayers.length; i++)

    {

    selLayers[i].startTime = (selLayers[i].inPoint = selLayers[i].startTime) + i * offset;

    }

    app.endUndoGroup();

  • Dan Ebberts

    December 29, 2021 at 5:46 pm

    Try changing this:

    selLayers[i].startTime = (selLayers[i].inPoint = selLayers[i].startTime) + i * offset;

    to this:

    selLayers[i].startTime -= selLayers[i].inPoint - i*offset;

  • Vincenzo Imbimbo

    December 30, 2021 at 9:27 am

    It worked, but now everytime they get sequenced they begin in the start of the composition instead of the inPoint of the Layers, what can i do?

  • Dan Ebberts

    December 30, 2021 at 11:25 am

    Ah, OK. The loop should probably be like this:

    var tStart = selLayers[0].inPoint;
    for (var i = 0; i < selLayers.length; i++)
    {
      selLayers[i].startTime -= selLayers[i].inPoint - tStart - i*offset;
    }
  • Vincenzo Imbimbo

    December 30, 2021 at 11:44 am

    Thank you Dan!! Now it’s working perfectly, but there’s another thing that i want to add, it is possible to keep adding the sequence to the already sequenced layers? Example: i sequence the layers by 5 frames, if i click it again now they’ll be sequenced by 10 frames, and if i click again they’ll be sequenced by 15 frames, and so on… is it possible?

  • Dan Ebberts

    December 30, 2021 at 1:14 pm

    It seems like that would be a bit of a bookkeeping headache. I think you’d have to keep track of the previous layer selection set, then on the next entry, check to see if selLayers is exactly the same as it was last time, and if so, bump a counter that you would then use as a multiplier for i*offset. Might be kind of confusing for the user too (unless it’s just you).

  • Vincenzo Imbimbo

    December 30, 2021 at 2:18 pm

    It was working before, when i had this code:

    selLayers[i].startTime = (selLayers[i].inPoint = selLayers[i].startTime) + i * offset;

    But now that i have changed the “=” to “-=” it becomes static, i mean, if i click on the “Execute button” of the script it works but that’s it, it doesn’t add a new value to the already sequenced layers, because there is no new value that can be added, it works just fine but only once, if i want to add more frames to that sequence i need to type a new number and click again on the execute button, and i think that this workflow is a little time consuming (i mean, having to type a new number every time i want to add more frames to the sequence instead of sequencing that number of frames that i’ve already wrote every time i click the button). I now that it’s possible to achieve what i’m asking for because i have an script that already does that, but is an jsxbin file so i can’t look at the code, i feel like i’m getting closer but i don’t know what should i do.

    Thanks again for all the help Dan!

    Maybe you will tell me: why don’t you use that script that you already have? And that’s because this “Sequence Layers” is just one of the functions than i’m trying to incorporate to a very complete and useful script for all my subscribers at Eje in Motion.

    I’m really new to writing scripts but i know that i will achieve it, and i’m having really fun, it feels like magic when you click that “play” button and see the Script doing exactly what you want it to do.

  • Dan Ebberts

    December 30, 2021 at 4:44 pm

    >Maybe you will tell me: why don’t you use that script that you already have?

    I’m sorry–you lost me. What script are you talking about?

  • Vincenzo Imbimbo

    December 30, 2021 at 4:58 pm

    pt_ShiftLayers by Paul Tuersley, what i mean is that the thing that i want to achieve has been already achieved by other scripts, but i can’t figure it out “how”, i need to know the “how” because i want to use this function in a custom script for the Motion Designers community. I was explaining the “why” i don’t use this script by Paul Tuersley, it is because i don’t really need this tool, i just want to learn how it was done to be incorporated in another script.

  • Vincenzo Imbimbo

    January 24, 2022 at 4:53 pm

    Hi Dan! i finally achieved what i was looking for.

    This was the modification that i did:

    var myCompTime = 0;

    selLayers[i].startTime = (selLayers[i].inPoint = selLayers[i].startTime) + myCompTime + i * offset;

    You know how can i do to sequence layers AND keyframes? I mean, right know is working fine with layers, but i want it to work also with keyframes, depending on what you have selected. Any thoughts?

    This is the code:

    var comp = app.project.activeItem;

    var err = this.selErr;

    if (this.checkActiveItem(comp)) throw(err);

    var selLayers = comp.selectedLayers.reverse();

    if (selLayers.length < 1) throw(err);

    var offset = parseFloat(pal.gr.gr2.framesEt.text) * comp.frameDuration;

    app.beginUndoGroup(this.scriptTitle);

    var tStart = selLayers[0].inPoint;

    for (var i = 0; i < selLayers.length; i++)

    {


    var myCompTime = 0;

    selLayers[i].startTime = (selLayers[i].inPoint = selLayers[i].startTime) + myCompTime + i * offset;

    }

    app.endUndoGroup();

Viewing 1 - 10 of 10 posts

Log in to reply.

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy