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 pmSo 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 pmYou 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 pmThanks 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 pmI 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 pmThat 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 pmIt’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 pmAssuming 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 amThank 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 amAnd 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 pmI haven’t tested it, but everywhere you see:
numKeys-1
change it to:
numKeys-3
Dan
Reply to this Discussion! Login or Sign Up