Skip to main content
Participant
April 5, 2022
Answered

Expression involving time and keyframe

  • April 5, 2022
  • 3 replies
  • 486 views

Hello!

 

I'm learning expressions and want to write an "if / else" expression to make the scale of a shape do something like what I've written below. I just don't know the proper coding, or if you can even reference a keyframe's time value on the timeline.

 

If (time is less than the time value of this specific keyframe)

Scale = the value on such and such slider

Else (if time is more than that key frame's time value)

Scale = 100%

 

Basically I'm wanting the scale to equal the value on a that slider only while a shape moves from point A to point B. But once the shape gets to point B (that keyframe) I don't want the scale to be affected by that slider anymore, so that the scale stays 100% for the rest of the animation. 

 

Hope that all made sense! Would love to learn how to do this. Thanks.

This topic has been closed for replies.
Correct answer Rick Gerard

I used two Position keyframes to control the Scale property for this example.

newScale = effect("Slider Control")("Slider");
posKframe = transform.position.key(2).time;
if (time < posKframe){
	[newScale, newScale];
}
else{
	value;
}

 The expression says that the New Scale is equal to the slider value. The second line looks at the Position keyframe on the same layer and extracts the time. The If argument says if the time is less than the time of the second Position keyframe, make the X and Y scale values equal to the new Scale from the Slider Control. If time is greater than the time of the second Position keyframe, the Scale reverts to the original Scale value of the layer.

3 replies

Rick GerardCommunity ExpertCorrect answer
Community Expert
April 7, 2022

I used two Position keyframes to control the Scale property for this example.

newScale = effect("Slider Control")("Slider");
posKframe = transform.position.key(2).time;
if (time < posKframe){
	[newScale, newScale];
}
else{
	value;
}

 The expression says that the New Scale is equal to the slider value. The second line looks at the Position keyframe on the same layer and extracts the time. The If argument says if the time is less than the time of the second Position keyframe, make the X and Y scale values equal to the new Scale from the Slider Control. If time is greater than the time of the second Position keyframe, the Scale reverts to the original Scale value of the layer.

Participant
April 7, 2022

Thank you! This sounds like exactly what I'm looking for.

Peru Bob
Community Expert
Community Expert
April 6, 2022

Moved to the After Effects forum.

John T Smith
Community Expert
Community Expert
April 6, 2022

When you post a question you always need to tell the program you are using
There are MANY programs in a full subscription, plus other non-subscription programs
Please post the exact name of the Adobe program you use so a Moderator may move this message to that forum