ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Reference to previous key frame

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Pablo Levin
Reference to previous key frame
on Sep 20, 2016 at 5:39:53 pm
Last Edited By Pablo Levin on Sep 20, 2016 at 5:41:54 pm

Hi all! I am needing to make reference to the previous keyframe. So then I can use something like .valueAtTime(prevKeyframe.time). I'm trying differents things since two days, but I canĀ“t figure it out.


Return to posts index

Dan Ebberts
Re: Reference to previous key frame
on Sep 20, 2016 at 5:51:39 pm

Depending on what you're trying to do, this might work:


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



Dan



Return to posts index

Pablo Levin
Re: Reference to previous key frame
on Sep 20, 2016 at 8:40:59 pm

Yes Dan! You are a genious!!

Thanks again!!!


Return to posts index


Pablo Levin
Re: Reference to previous key frame
on Sep 20, 2016 at 8:41:40 pm

*genius


Return to posts index

Arthur Bourquin
Re: Reference to previous key frame
on Jan 12, 2019 at 9:50:56 am

Hi guys,

I wrote this one for "previousKey".

So you can easily choose ".value" / ".time" / ".index" at the end.

previousKey :
function F(a){if(a<=time)return 0 else return 1 }key(Math.max(Math.min(nearestKey(time).index-F(nearestKey(time).time),numKeys),1)).value
function F(a){if(a<=time)return 0 else return 1 }key(Math.max(Math.min(nearestKey(time).index-F(nearestKey(time).time),numKeys),1)).time
function F(a){if(a<=time)return 0 else return 1 }key(Math.max(Math.min(nearestKey(time).index-F(nearestKey(time).time),numKeys),1)).index

if needed, this is for nextKey :
function F(a){if(a<=time)return 0 else return 1 }key(Math.max(Math.min(nearestKey(time).index+1-F(nearestKey(time).time),numKeys),1)).value
function F(a){if(a<=time)return 0 else return 1 }key(Math.max(Math.min(nearestKey(time).index+1-F(nearestKey(time).time),numKeys),1)).time
function F(a){if(a<=time)return 0 else return 1 }key(Math.max(Math.min(nearestKey(time).index+1-F(nearestKey(time).time),numKeys),1)).index

Explainations:
function F(a) will test if nearestKey is before or after current time
Math.max/Math.min will exclude some errors

works for me in CS6
works with arrays

function F(a){if(a&lt;=time)return 0 else return 1 }key(Math.max(Math.min(nearestKey(time).index-F(nearestKey(time).time),numKeys),1)).value


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2019 CreativeCOW.net All Rights Reserved
[TOP]