Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Toggle Hold value between keyframes?

  • Toggle Hold value between keyframes?

    Posted by Ronan De lacy on March 11, 2019 at 11:54 am

    Hello all,

    I have a text layer, that’s set up to pull data from a text file. I’m taking values from sliders on separate layers to each keyframe on the timeline.

    Everything is working, however, the value animates between the keyframes, and I’d like it to to snap at each keyframe. I have toggle hold keyframes applied, but they’re being over ridden by the expression.

    Any ideas on how I may be able to achieve this? see expression below.

    Many thanks,
    Ronan

    key1 = thisComp.layer("range-1").effect("Slider Control")("Slider");
    key2 = thisComp.layer("range-2").effect("Slider Control")("Slider");
    if(numKeys > 1){
    linear(time,key(1).time,key(2).time,key1,key2);
    }else{
    key1;
    }

    Ronan De lacy replied 7 years, 2 months ago 3 Members · 7 Replies
  • 7 Replies
  • Dan Ebberts

    March 11, 2019 at 2:07 pm

    Try it this way:

    key1 = thisComp.layer(“range-1”).effect(“Slider Control”)(“Slider”);
    key2 = thisComp.layer(“range-2”).effect(“Slider Control”)(“Slider”);
    if(numKeys > 1){
    time < key(2).time ? key1 : key2;
    }else{
    key1;
    }

    Dan

  • Scott Mcgee

    March 11, 2019 at 2:09 pm

    Hi,

    Your expression tells it to animate between 1 and 2 between those values. So that’s the reason for that.

    If you want it to snap. You need to look at nearestKey expression.

    Quickly pinched this from Dan, if no one else responded. This is kind of what you are after but will need to play with it a little.

    This essentially snaps to the value you the nearest keyframe

    p = transform.opacity;
    n = 0;
    if (p.numKeys > 0){
    n = p.nearestKey(time).index;
    if (p.key(n).time > time) n–;
    }
    if (n> 0)
    p.valueAtTime(p.key(n).time)
    else
    value

  • Ronan De lacy

    March 11, 2019 at 3:10 pm

    Thanks Dan, this worked a treat!. If I wanted to set this to use more than 2 keyframes, how would I go about that?

    Many Thanks,
    Ronan

  • Ronan De lacy

    March 11, 2019 at 3:12 pm

    Hey Scott – Thanks so much for your reply.

    Dan’s solution got me there, but I’m going to explore your solution, too.

    Cheers,
    Ronan

  • Scott Mcgee

    March 11, 2019 at 3:15 pm

    Just realised as I typed mine, Dan already sent you something.

    What he’s put is a cleaner version of what I pinched of his. So if you can benefit from it for something else in the future, great, but Dan’s looks the part for the job.

    🙂

  • Dan Ebberts

    March 11, 2019 at 3:46 pm

    You could extend the idea like this:


    key1 = thisComp.layer("range-1").effect("Slider Control")("Slider");
    key2 = thisComp.layer("range-2").effect("Slider Control")("Slider");
    key3 = thisComp.layer("range-3").effect("Slider Control")("Slider");
    if(numKeys > 2){
    if (time < key(2).time){
    key1;
    }else if (time < key(3).time){
    key2;
    }else{
    key3;
    }
    }else{
    key1;
    }

    If you have a lot of keyframes though, there’s probably a more compact way to do it.

    Dan

  • Ronan De lacy

    March 12, 2019 at 11:42 am

    Thanks so much, Dan. You’re a life saver!!

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