Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Forums Adobe After Effects Expressions Using expression to loop layer and trim Work Area?

  • Using expression to loop layer and trim Work Area?

  • Xavier Paredes

    August 21, 2018 at 3:26 am

    I have about 300 short videos of varying lengths ranging from 00:00:00:07 (7 frames) to 00:00:33:02 (33 seconds and 2 frames). I have to loop most of them because they are too short.

    I have done some research and found that I can use expressions to do looping. For example, the expression below will loop the layer 10 times.

    Also, by design the expression will freeze the video that’s past the last loop, therefore, I will need to trim the work area at the location of the last frame of the last loop. What would be the easiest/quickest way to do this?

    Is it possible to perhaps add something to the expression so that a marker is added to that last frame of the last loop so I can quickly find it and do the trim?

    Lastly, is there a way to add something to the expression that can automatically trim the work area? I don’t think so but I figured I’d ask.

    Any other techniques would be appreciated since I have so many videos to deal with and my carpal is acting up. : )

    Thank you for any help.

    nLoops = 10;
    if (numKeys > 1){
    loopDur = key(numKeys).time - key(1).time;
    n = Math.floor((time - key(1).time)/loopDur);
    if (n < nLoops){
    t = (time - key(1).time)%loopDur;
    valueAtTime(key(1).time + t);
    }else{
    valueAtTime(key(numKeys).time);
    }
    }else
    value;

    Xavier

  • Scott McGee

    August 21, 2018 at 7:57 am

    You can do it with a script, otherwise you have to manually trim. Expressions don’t trim your Comp.

    So you could implement your expression into said script. Add a text box for time length, so it’s a bit more dynamic. Hit the submit button and that will trim your activeComp and add the expression to your layer.

    I do something similar for idents I used to make that ranged between 2-15 seconds.

    If you want to trim the layer and not the comp. I guess you could add an opacity expression to switch itself off, but again if that’s the case. Manually or script is the only way.

  • Xavier Paredes

    August 21, 2018 at 12:46 pm

    Hi Scott,

    Thank you for your reply. You wouldn’t happen to have the script that you used to trim the comp handy would you?

    I don’t know how to script unfortunately :/

    Xavier

  • Xavier Paredes

    August 21, 2018 at 12:53 pm

    Forgot to ask, how would the script know where to trim the comp? Would it be able to use the marker I was hoping to be able to create with the expression (please see my original post)?

    Xavier

  • Scott McGee

    August 21, 2018 at 4:30 pm

    I’d have to dig it out as I don’t work for that company anymore, but there is no reason why you couldn’t use it to do it based on a marker, but I did mine based on seconds.

    Unless Someone answers before hand I will come back to you maybe later on or tomorrow

  • Scott McGee

    August 22, 2018 at 8:49 am

    I’ve updated it to include frames.

    There might be an easier way to add frames and seconds, but I’ve bodged it this way and it works fine.

    var win = new Window (“palette”,”Comp Duration”,undefined);

    var title = win.add(‘statictext’,undefined,”Seconds”);
    var myTextSec = win.add(‘edittext’,[100,120,150,140],0);
    var title2 = win.add(‘statictext’,undefined,”frames”);
    var myTextFrames = win.add(‘edittext’,[100,120,150,140],0);
    var btn = win.add(‘button’,undefined,”Submit”);

    btn.onClick = function(){
    var myComp = app.project.activeItem;
    var text1 = myTextSec.text;
    var text2 = myTextFrames.text;
    myComp.duration = text1;
    myComp.duration += text2*myComp.frameDuration;// set duration
    }

    win.show();

    All it’s doing is changing the comp based on seconds, then changing it a second time to add the frames separately. If someone can offer a way to change it in one line cool. Otherwise this will work fine for you.

  • Scott McGee

    August 22, 2018 at 9:47 am

    Forgot to mention that if you want to update comp length based on the outPoint of a selected layer.

    var myComp = app.project.activeItem;
    var myLayer = myComp.selectedLayers[0];
    myComp.duration = myLayer.outPoint;

    or you can do it based on cursor of time

    var myComp=app.project.activeItem;
    myComp.duration = myComp.time;

    So these are a few other options available to you.

  • Sami Bayley

    October 11, 2021 at 3:59 pm

    Hey Scott, sorry this was a while ago. I’m having trouble.

    Should this work?

    var win = new Window (“palette”,”Comp Duration”,undefined);

    var title = win.add(‘statictext’,undefined,”Seconds”);

    var myTextSec = win.add(‘edittext’,[100,120,150,140],0);

    var title2 = win.add(‘statictext’,undefined,”frames”);

    var myTextFrames = win.add(‘edittext’,[100,120,150,140],0);

    var btn = win.add(‘button’,undefined,”Submit”);

    btn.onClick = function(){

    var myComp = app.project.activeItem;

    var myLayer = myComp.selectedLayers[0];

    myComp.duration = myLayer.outPoint;// set duration

    }

    win.show();

  • Scott McGee

    October 11, 2021 at 4:31 pm

    Hey Sami,

    Not too sure what you might be having trouble with but just incase.

    If you’ve copied and pasted into Extendscript, make sure “” aren’t “”. I’ve noticed the code I’ve copied and pasted back then did that has done that. So they’ll need to be swapped. Same goes for ” and ‘’

    Once these have been replaced then it should work no problem.

    If not, can you specify what the error is coming back with, but it should be saying something on the lines of.

    unable to execute script at line 1. syntax error

    If it’s saying something like this, then it’s the “” and ”.

    Hope that helps.

Viewing 1 - 9 of 9 posts

Log in to reply.

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