shinsuke matsumoto's blog thing.

One day in 2015, I think it’s annoying to offset the selected layers time when I need to do so with a tons of layers. So I wrote this little script for myself. It’s not perfect in some cases, I feel. But I decided to share it because some mographers gave me a positive feedback on Twitter. Thanks, folks!

Okay, here’s the code for you. This one called “layersTimeOffset” is to offset the layers time to current time indicator while keeping the layers relative inpoints. Please take a look.

[Script Code]

app.beginUndoGroup("Layers Time Offset");
var curComp = app.project.activeItem;
if(curComp != null && curComp instanceof CompItem){
    var selectedLayers = curComp.selectedLayers;
    if(selectedLayers.length > 0){
        var layerObjArray = new Array();
        for(var i = 0; i < selectedLayers.length; i++){
            layerObjArray.push([selectedLayers[i], selectedLayers[i].startTime, selectedLayers[i].inPoint]);
        var sortedLayers = layerObjArray.sort(function(a, b){
            if(a[2] < b[2]){ return -1; } if(a[2] > b[2]){
                return 1;
            return 0;
        for(var j = 0; j < sortedLayers.length; j++){ if(sortedLayers[0][1] > sortedLayers[0][2]){
                sortedLayers[j][0].startTime = curComp.time + (sortedLayers[0][1] - sortedLayers[0][2]) + sortedLayers[j][1] - sortedLayers[0][1];
            } else if(sortedLayers[0][1] < sortedLayers[0][2]){ sortedLayers[j][0].startTime = curComp.time - (sortedLayers[0][2] - sortedLayers[0][1]) + sortedLayers[j][1] - sortedLayers[0][1]; } else { sortedLayers[j][0].startTime = curComp.time + sortedLayers[j][1] - sortedLayers[0][1]; } if(sortedLayers[j][1] > sortedLayers[j][2]){
                sortedLayers[j][0].inPoint = sortedLayers[j][0].startTime - (sortedLayers[j][1] - sortedLayers[j][2]);
            } else if(sortedLayers[j][1] < sortedLayers[j][2]){
                sortedLayers[j][0].inPoint = sortedLayers[j][0].startTime + (sortedLayers[j][2] - sortedLayers[j][1]);
    } else {
        alert("Select a layer at least.", "Layers Time Offset");
} else {
    alert("Select a composition first.", "Layers Time Offset");


[Quick Explanation]
Copy the code & past them into Adobe ExtendScript Toolkit. And in AE, select layers, then running the script. So layersTimeOffset script will offset the layers time to current time indicator while keeping the layers relative inpoints.

If you have a great script called “ft-Toolbar2” from aescripts, it’s ultra easy to use this script. Create the new button as Javascript in the setting menu in ft-Toolbar2, and then copy & paste the code into the command field like below. So you can offset the layers time with one click.

Anyway, I would much appreciate it if you could give me a feedback. So please don’t hesitate to get in touch with me if you find some errors or better ways. And if you have any request for the series, hit me up on my Twitter. And if you don’t have time to read my crappy article, please follow & check my codes on my GitHub Gist.


2 Responses to “Crap Sharing for AE Scripting: layersTimeOffset”

  1. Jason Jantzen

    Hey Shinsuke! For some reason when I do this with an MP4, it aligns the in points, but it also tries to align the outpoints, resulting in 1 frame per layer, if you know what I mean. I’m on a PC Windows 7. Let me know if you get the same results. Thanks for your awesome brains!

    • beatgram

      Hi, Jason.
      Thank you for playing around with my code. I didn’t try my code with MP4, so I’ll test it later. I’m not sure but I feel like it’s AE problem with MP4. Anyway, I’ll contact you after I check it.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Basic HTML is allowed. Your email address will not be published.

Subscribe to this comment feed via RSS

%d bloggers like this: