ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Return the index value of the previous keyframe on a different layer

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Paul Connors
Return the index value of the previous keyframe on a different layer
on Mar 28, 2020 at 12:20:45 am

Hello. I have a null layer called "Controller" that has a Slider Effect on it named "Slider". This slider effect has five keyframes on it spread out over time. I then have a text layer named "Keyframe Index" and I'd like the Source text to return the index value of the previous keyframe on the slider.

For example, I have a keyframe on the slider at 0 sec, 1 sec, 5 sec, 6 sec, and 11 sec. When the playhead is between 0 and 1 sec I'd like the source text to display "1" (because the first keyframe is at 0 sec). When the playhead is between 1 sec and 5 sec I'd like the source text to display "2" (because the second keyframe is at 1 sec). When the playhead is between 5 sec and 6 sec I'd like the source text to display "3". When the playhead is between 6 sec and 11 sec I'd like the source text to display "4". And when the playhead is after 11 sec I'd like the source text to say "5".

Essentially I'm just looking for the source text to display the index of the previous keyframe on the slider layer. I hope that makes sense. Thank you.


Return to posts index

Dan Ebberts
Re: Return the index value of the previous keyframe on a different layer
on Mar 28, 2020 at 6:16:12 am

This should work:


s = thisComp.layer("Controller").effect("Slider Control")("Slider");
n = 0;
if (s.numKeys > 0){
n = s.nearestKey(time).index;
if (time < s.key(n).time)n--;
}
n



Dan



Return to posts index

Paul Connors
Re: Return the index value of the previous keyframe on a different layer
on Mar 28, 2020 at 1:36:51 pm

This worked perfectly. Thanks very much Dan!


Return to posts index

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