Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Changing keyframe times using an expression

  • Changing keyframe times using an expression

    Posted by Tymo Ooijevaar on May 17, 2016 at 4:40 pm

    So i am trying to figure out a way to more keyframes to a time relative to the beginning/end of another layer, or maybe even using a slider control. I want to do this because it’s annoying having to move the keyframes every time i change the end of the composition. any ideas on how to do this?

    Ivan de Wolf replied 3 years, 9 months ago 3 Members · 11 Replies
  • 11 Replies
  • Dan Ebberts

    May 17, 2016 at 6:43 pm

    You can’t move the keyframes with an expression, buy you can manipulate the timing of the result. There are a number of ways to do it, depending on what you need to do exactly, but here’s an example to get you headed in the right direction. Apply this expression to keyframed property, and it will offset the keyframe timing by the difference between keyframed layer and the other layer’s in points:

    delta = thisComp.layer(“other layer”).inPoint – inPoint;
    valueAtTime(time – delta)

    Dan

  • Tymo Ooijevaar

    May 17, 2016 at 8:00 pm

    Thanks for the help, but unfortunately that expression doesn’t do what i wanted it to do. Let me explain it again but this time using a screenshot as well.

    So basicly there’s my 2 keyframes that i’ve set to make an animation, and there’s the “Outro” layer at the top of wich the end is touching the end of my range. And what i want to happen is that when i change the end of the range and more the “Outro” layer i want the keyframes to move with it. Is it possible to achieve this?

  • Dan Ebberts

    May 17, 2016 at 8:42 pm

    I think that would be like this:

    delta = thisComp.layer(“Outro”).inPoint – key(numKeys).time;
    valueAtTime(time – delta)

    Dan

  • Tymo Ooijevaar

    May 17, 2016 at 8:50 pm

    That doesn’t seem to work at all, none of the keyframes get moved and even worse the keyframe values get changed. I did try something from this page: https://forums.creativecow.net/thread/227/10716 , but that didn’t work either for some reason. I might also need to mention that there are 2 more keyframes at the beginning of the timeline.

  • Dan Ebberts

    May 17, 2016 at 9:14 pm

    It’s important to remember that the keyframes are not actually going to move, just the values.

    > I might also need to mention that there are 2 more keyframes at the beginning of the timeline.

    That’s a very important detail to leave out. So what you really want is the 2-keyframe fade should be tied to the in point of the Outro, is that correct?

    Dan

  • Dan Ebberts

    May 17, 2016 at 9:34 pm

    Assuming that is what you’re trying to do, try it this way:


    ip = thisComp.layer("Outro").inPoint;
    d = key(numKeys).time - key(numKeys-1).time;
    if (time > (ip - d)){
    t = key(numKeys-1).time + (time - (ip - d));
    }else{
    t = Math.min(time,key(numKeys-1).time);
    }
    valueAtTime(t)

    Dan

  • Tymo Ooijevaar

    May 18, 2016 at 7:22 am

    Thank you so much! even though you can’t visualy see the keyframes move the values do, wich is excactly what i needed. And I’m sorry for not telling you about those 2 beginning keyframes at first.

  • Tymo Ooijevaar

    May 18, 2016 at 8:05 am

    And what to do if there are 8 keyframes in total and i want to move the last 4?

  • Dan Ebberts

    May 18, 2016 at 1:41 pm

    I haven’t tested it, but everywhere you see:

    numKeys-1

    change it to:

    numKeys-3

    Dan

  • Tymo Ooijevaar

    May 18, 2016 at 6:09 pm

    That seems to work just nicely, thanks for all the help!

Page 1 of 2

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