Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Changing Keyframe Time Through Expressions

  • Changing Keyframe Time Through Expressions

    Posted by Amir Aizat on August 7, 2016 at 6:01 pm

    Hello, I’m trying to create a template for my team’s video editors working with Premiere Pro.

    It’s supposed to be a transition with adjustable speed by keying s, m, or f in Premiere’s Live Text templates feature.

    English is not my first language, and I am a rookie with expressions (self-taught to boot) so please bear with me.

    The transition has 4 keyframes, 2 in and 2 out. Fast transition will result in -1s for keyframe 2 and +1s for keyframe 3 and the opposite for slow transition. Medium speed will not change the timing of the keyframes. The reason I want to manipulate keyframes instead of using the ease expression is because I want to preserve my speed graph.

    So far I came up with this:

    //Transition Speed
    var mod2 = thisComp.layer("Speed (s/m/f)");
    var mod2spd = mod2.text.sourceText;

    var ti = thisComp.layer ("Transition A");
    var tp = ti.transform.position;
    var tpk2 = tp.key(2).time;
    var tpk3 = tp.key(3).time;

    if (mod2spd == "s" || mod2spd == "S")
    tpk2+1, tpk3-1
    else if (mod2spd == "m" || mod2spd == "M")
    tpk2, tpk3
    else if (mod2spd == "f" || mod2spd == "F")
    tpk2-1, tpk3+1
    else
    tpk2, tpk3

    valueAtTime
    Obviously I received the orange error message but the error message isn’t helping either, it says “Error at line 0 in the property “Position” of layer 3 (‘Transition A’) in comp ‘Helper Transition’. Object of type Function found where a Number, Array, or Property is needed., an expression was disabled as a result of an error.”

    Can someone explain my mistake and how do I achieve what I wanted to make?

    Thank you.

    Amir Aizat replied 10 years ago 2 Members · 2 Replies
  • 2 Replies
  • Dan Ebberts

    August 7, 2016 at 6:52 pm

    You can’t change keyframe times with expressions, but this position expression for your transition layer should do what you want:


    mod2 = thisComp.layer("Speed (s/m/f)");
    mod2spd = mod2.text.sourceText.toLowerCase();

    t1 = key(1).time;
    t2 = key(2).time;
    t3 = key(3).time;
    t4 = key(4).time;

    doingIn = time < (t2+t3)/2;

    t = time;
    if (mod2spd == "s"){
    if(doingIn){
    t = linear(time,t1,t2+1,t1,t2);
    }else{
    t = linear(time,t3-1,t4,t3,t4);
    }
    }else if (mod2spd = "f"){
    if(doingIn){
    t = linear(time,t1,t2-1,t1,t2);
    }else{
    t = linear(time,t3+1,t4,t3,t4);
    }
    }
    valueAtTime(t)

    Dan

  • Amir Aizat

    August 7, 2016 at 7:03 pm

    Hi Dan,

    That is amazing! I’ve learned something new today, and I’ve always learned from your other examples.

    Many thanks!

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