Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Control the last 2 keyframes by the length of the layer

  • Control the last 2 keyframes by the length of the layer

    Posted by Hiro Ober on October 6, 2015 at 4:04 am

    I don’t know if it’s possible at all. But I want to write some expressions that allow me to make the last 2(or specified number of keyframes is even better) keyframes of position always stay at the end of the layer. I’ll try to explain it a bit better:

    I have a layer with some slide in/out animation on position property at the beginning and the end of the layer, is it possible to make the last 2 keyframes always stay at the end of the layer even the layer’s length is changed? The normal way is to trim the layer to a desired length, and then manually move the last 2 keyframes to the end of the layer, which is a lot of work if you have more than hundred of layers.

    Hiro Ober replied 8 years, 9 months ago 2 Members · 5 Replies
  • 5 Replies
  • Dan Ebberts

    October 6, 2015 at 4:45 am

    There are probably all kinds of things you could do to break this, but I think this would be the basic idea:


    keysToMove = 2;
    if (numKeys > keysToMove){
    t1 = key(numKeys-keysToMove+1).time;
    delta = key(numKeys).time - t1;
    t2 = outPoint - delta;
    if (time < t2)
    valueAtTime(time*t1/t2)
    else
    valueAtTime(t1 + (time - t2));
    }else
    value

    Dan

  • Hiro Ober

    October 6, 2015 at 8:25 pm

    OMG!! It works like a charm!

    It took me a while to understand it, thank you so much Dan!

  • Hiro Ober

    October 6, 2015 at 10:31 pm

    Hmmmm…when I’m trying this fantastic expressions, I found another issue. Why won’t it work with an overshoot expression? I don’t see any conflict in these 2 script. Haven’t sorted that out. I’d be really appreciated if you may have time to point me to the right direction.

    I have pasted the overshoot expression I’m using on the same property together with the above one Dan has written.

    Thanks!

    if (numKeys > 0){
    n = nearestKey(time).index;
    if (key(n).time > time){
    n--;
    }
    }

    if (n == 0){
    t = 0;
    }else{
    t = time - key(n).time;
    }
    if (n > 0 && t &lt; 1){
    v = velocityAtTime(key(n).time - thisComp.frameDuration/10);
    amp = .1;
    freq = 2.0;
    decay = 5.0;
    value + v*amp*Math.sin(freq*t*2*Math.PI)/Math.exp(decay*t);
    }else{
    value;
    }

  • Dan Ebberts

    October 6, 2015 at 10:47 pm

    You can’t just paste one expression after another and expect them cooperate. The final result of the expression is always the result of the last operation/calculation–so the first expression will most likely have no impact at all.

    Generally, you have to store the result of the first expression into a variable and then work that variable into the calculations of the second expression.

    Dan

  • Hiro Ober

    October 7, 2015 at 3:24 am

    Thanks again for the explanation! To be honest, I’ve never used multiple expressions on one property before, so I’ve spent 3 hours googling and try to learn how to save the result of the first expression to a variable, haven’t figured it out though…can I ask how?

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