Highlighted

Expression count previous keyframes

Engaged ,
Jan 17, 2018

Copy link to clipboard

Copied

I need to have the an offset value count how many keyframes on a null layer previous to the current time.

Suggestions?

Adobe Community Professional
Correct answer by Rick Gerard | Adobe Community Professional

Do you need to delay the reveal so it happens after a keyframe? If all you need to do is count keyframes than that is pretty easy. nearestKey(time).index will give you the number of the keyframe nearest the current time. If you need to make the switch exactly on a keyframe or a specific number of frames before or after then it is going to require a bunch more language.

Let's say your keyframes were set on Null 1's position property. The expression to count keyframes would look like this:

thisComp.layer("Null 1").transform.position.nearestKey(time).index

You would set up your text animator to use Index and Words. The new number would appear as soon as the half way point between keyframes is passed. It will start with 1.

Views

556

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Expression count previous keyframes

Engaged ,
Jan 17, 2018

Copy link to clipboard

Copied

I need to have the an offset value count how many keyframes on a null layer previous to the current time.

Suggestions?

Adobe Community Professional
Correct answer by Rick Gerard | Adobe Community Professional

Do you need to delay the reveal so it happens after a keyframe? If all you need to do is count keyframes than that is pretty easy. nearestKey(time).index will give you the number of the keyframe nearest the current time. If you need to make the switch exactly on a keyframe or a specific number of frames before or after then it is going to require a bunch more language.

Let's say your keyframes were set on Null 1's position property. The expression to count keyframes would look like this:

thisComp.layer("Null 1").transform.position.nearestKey(time).index

You would set up your text animator to use Index and Words. The new number would appear as soon as the half way point between keyframes is passed. It will start with 1.

Views

557

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jan 17, 2018 1
Adobe Community Professional ,
Jan 17, 2018

Copy link to clipboard

Copied

You'll need to clarify a bit. You can use valueAtTime or look for nearest, previous, or next keyframe. What exactly are you trying to do?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 17, 2018 0
Engaged ,
Jan 17, 2018

Copy link to clipboard

Copied

Basically I have text that reveals itself line by line. This is controlled by an animator control offset.

I need this offset value to be changed over time based on the count of previous keyframes on another layer,

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 17, 2018 0
Adobe Community Professional ,
Jan 17, 2018

Copy link to clipboard

Copied

Do you need to delay the reveal so it happens after a keyframe? If all you need to do is count keyframes than that is pretty easy. nearestKey(time).index will give you the number of the keyframe nearest the current time. If you need to make the switch exactly on a keyframe or a specific number of frames before or after then it is going to require a bunch more language.

Let's say your keyframes were set on Null 1's position property. The expression to count keyframes would look like this:

thisComp.layer("Null 1").transform.position.nearestKey(time).index

You would set up your text animator to use Index and Words. The new number would appear as soon as the half way point between keyframes is passed. It will start with 1.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 17, 2018 0
New Here ,
Oct 12, 2020

Copy link to clipboard

Copied

Rick,

 

I appreciate your response to the original poster, the code works great! You stated a little more language was needed to action the count ON each key frame; would you be able to share that with me? I own a kill counter youtube channel and currently edit each text box seperately, and as you can imagine, this takes an absolute age to edit one video with up to 3000 kills.  

 

So I also have anohter question; am i able to use keyframes to trigger a sound FX too?

 

Very many thanks in advance!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 12, 2020 0
Adobe Community Professional ,
Oct 12, 2020

Copy link to clipboard

Copied

You can retrieve the time of the nearest keyframe or the number of the nearest keyframe by starting with this simple expression:

ref = thisComp.layer("Reference Layer");
keyTime = ref.position.nearestKey(time).time;
keyIndex = ref.position.nearestKey(time).index;

In this case, I'm looking at the Position property of a layer named "Reference Layer" and returning the keyframe time and the keyframe number. 

 

You can then use if/else statements, accumulators, or other methods to make changes to other properties.

 

You cannot cue audio tracks using keyframes but you could time remap an audio layer, extend it. set a couple of keyframes at the start and end of a sound effect, then use an if statement to start playing the sound when a new keyframe is reached. This would be the same kind of thing you would use to drive time remapped mouth shapes to animate a character.

 

I don't have time to figure out all of the code for you but if you are good with Expressions and do a little research, you should be able to make something happen when you get to a keyframe on another property.

 

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 12, 2020 0
New Here ,
Oct 12, 2020

Copy link to clipboard

Copied

Rick, thank you very much for this; I will get to work on it and see what I can make of it! I appreciate your time answering 🙂

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 12, 2020 0
Adobe Community Professional ,
Oct 12, 2020

Copy link to clipboard

Copied

This should give you the time of the previous keyframe for any property.

ref = thisComp.layer("Reference Layer").position;
keyTime = ref.nearestKey(time);

if (keyTime.time <= time)
	keyNumber = keyTime.index;
else
	keyNumber = keyTime.index - 1;

lastKeyTime = ref.key(keyNumber).time;

It might give you an idea of how to proceed. You could use the keyNumber of the last keyframe or the lastKeyTime to drive other things. Maybe it will point you in the right direction. I find it useful to apply expressions like this to a text layer's Source Text property so I can see exactly what I'm getting. 

 

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 12, 2020 0