Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Forums Adobe After Effects Expressions Use script to freeze on last frame for 2 seconds

  • Use script to freeze on last frame for 2 seconds

  • Rob Packer

    November 16, 2021 at 2:41 am

    I am attempting to freeze a layer (vidL) on it’s last frame, and extend the layer and composition by 2 seconds.

    Using the code:

    vidL.timeRemapEnabled = true;

    vidL.property(“timeRemap”).setInterpolationTypeAtKey(1,KeyframeInterpolationType.HOLD);

    results in the layer freezing from the first frame.

    The following function throws an error code# 1: Unable to call “setValueAtTime” because of parameter 2. Value 19.96 out of range 0 to 18. However, when the code is halted, the freeze on last frame has worked, but not extending the layer.

    function freezeFrame(){
    vidL.startTime = 0;
    var vidLength = vidL.outPoint;

    compVideo.duration = vidLength + 2;
    vidL.timeRemapEnabled = true;

    var timeRemapProp = vidL.property(“ADBE Time Remapping”);
    var currTime = vidL.outPoint;
    var lastTime = currTime + 1.96;
    timeRemapProp.setValueAtTime(currTime, lastTime);

    }

    Any help would be appreciated.


  • Meng Zhiqun

    November 16, 2021 at 4:29 am

    You can try this. if targeting layers is required, select them before executing the script. If not, use this without selecting any layers.

    var projComp = app.project.activeItem;

    var selLay = projComp.selectedLayers;

    var addTime = 2;

    function addCompTime(item){

    if(item.timeRemapEnabled == false){

    item.timeRemapEnabled = true;

    item.outPoint = item.outPoint+ addTime;

    }else{

    item.outPoint = item.outPoint+ addTime;

    }

    }

    app.beginUndoGroup("setOutPoint");

    if(selLay.length > 0){//Select layers in comp

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

    var curLay = selLay[i];

    try{

    addCompTime(curLay);

    }catch(e){

    curLay.outPoint += addTime;

    }

    }

    }else{

    projComp.duration += addTime;

    for(var i = 1; i <= projComp.numLayers; i++){

    var curNSLay = projComp.layer(i);

    if(curNSLay.source.typeName != "Composition"){

    curNSLay.outPoint += addTime;

    }else{

    addCompTime(curNSLay);

    }

    }

    }

    app.endUndoGroup();

  • Rob Packer

    November 22, 2021 at 1:20 pm

    Thanks for the help Meng Zhiqun.

    Because I am the end user, and I have done error checking elsewhere in the script, I trimmed it down to this:

    var compVideo = app.project.item(3); // the video composition – which because of the naming structure will be the 3rd composition

    var vidL = compVideo.layer(4); // the actual video layer in the video composition – will be layer 4

    var addTime = 2;

    function freezeFrame(vidL){

    item.startTime = 0;

    compVideo.duration = item.outPoint+ addTime;

    item.timeRemapEnabled = true;

    item.outPoint = item.outPoint+ addTime;

    }

    Apologies for the late response.

  • Meng Zhiqun

    November 22, 2021 at 5:44 pm

    Hey Rob,

    Of course! My examples were done in a rush. So I’m glad u could proof read it. 🙂 Have fun!

Viewing 1 - 4 of 4 posts

Log in to reply.

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