Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Using frames instead of seconds in a script

  • Using frames instead of seconds in a script

    Posted by Sam Lanes on January 24, 2020 at 9:20 am

    I am currently writing a simple script that allows me to set a series of keyframes along a layer’s opacity.

    I have managed to get this to work, but the code is currently only working in seconds (which is where I have just put the second and third keyframes 0.1 and 0.2 seconds further along.

    This works, but I am wondering if it is possible to make the script refer to frames, so that I can be more accurate with the placement? Usually, I place three keyframes in place, 2 frames apart, and this is what I would like to replicate, if possible.

    var ActiveComp = app.project.activeItem;
    var selectedLayers = ActiveComp.selectedLayers;
    var numLayers = selectedLayers.length;
    var currentTime = selectedLayers.time;
    var time = app.project.activeItem.layer(1).time;

    if(numLayers == 0){
    alert("Select a layer");
    } else {
    selectedLayers[0].property("ADBE Transform Group").property("ADBE Opacity").setValueAtTime(time,100);
    selectedLayers[0].property("ADBE Transform Group").property("ADBE Opacity").setValueAtTime(time+0.1,0);
    selectedLayers[0].property("ADBE Transform Group").property("ADBE Opacity").setValueAtTime(time+0.2,100);
    };

    Sam Lanes replied 6 years, 6 months ago 2 Members · 2 Replies
  • 2 Replies
  • Andrei Popa

    January 24, 2020 at 1:18 pm

    comp.frameDuration is how long a frame is. Basically time = 2*comp.frameDuration means second frame.

    var ActiveComp = app.project.activeItem;
    var frameDuration = ActiveComp.frameDuration;
    var selectedLayers = ActiveComp.selectedLayers;
    var numLayers = selectedLayers.length;
    var currentTime = selectedLayers.time;
    var time = app.project.activeItem.layer(1).time *ActiveComp.frameDuration; ;

    if(numLayers == 0){
    alert("Select a layer");
    } else {
    selectedLayers[0].property("ADBE Transform Group").property("ADBE Opacity").setValueAtTime(time,100);
    selectedLayers[0].property("ADBE Transform Group").property("ADBE Opacity").setValueAtTime(time+2*frameDuration,0);
    selectedLayers[0].property("ADBE Transform Group").property("ADBE Opacity").setValueAtTime(time+4*frameDuration,100);
    };

    Andrei
    My Envato portfolio.

  • Sam Lanes

    January 24, 2020 at 2:44 pm

    Thanks Andrei – the frameDuration element is what I didn’t know! That works great.

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