ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Toggle Hold value between keyframes?

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Ronan De Lacy
Toggle Hold value between keyframes?
on Mar 11, 2019 at 11:54:56 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;
}


Return to posts index

Dan Ebberts
Re: Toggle Hold value between keyframes?
on Mar 11, 2019 at 2:07:17 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



Return to posts index

Ronan De Lacy
Re: Toggle Hold value between keyframes?
on Mar 11, 2019 at 3:10:45 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


Return to posts index


Dan Ebberts
Re: Toggle Hold value between keyframes?
on Mar 11, 2019 at 3:46:32 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



Return to posts index

Ronan De Lacy
Re: Toggle Hold value between keyframes?
on Mar 12, 2019 at 11:42:57 am

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


Return to posts index

Scott McGee
Re: Toggle Hold value between keyframes?
on Mar 11, 2019 at 2:09:00 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


Return to posts index


Ronan De Lacy
Re: Toggle Hold value between keyframes?
on Mar 11, 2019 at 3:12:54 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


Return to posts index

Scott McGee
Re: Toggle Hold value between keyframes?
on Mar 11, 2019 at 3:15:24 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.

:)


Return to posts index

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