Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Return the index value of the previous keyframe on a different layer

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

    Posted by Paul Connors on March 28, 2020 at 12:20 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.

    Paul Connors replied 6 years, 1 month ago 2 Members · 2 Replies
  • 2 Replies
  • Dan Ebberts

    March 28, 2020 at 6:16 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

  • Paul Connors

    March 28, 2020 at 1:36 pm

    This worked perfectly. Thanks very much Dan!

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