ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

If/Else Statement - Triggering Animation on First Marker and on Last Keyframe

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Eric Shepherd
If/Else Statement - Triggering Animation on First Marker and on Last Keyframe
on Feb 28, 2020 at 8:38:28 pm

This is a 2 parter.
Ive got a subtitle text layer (.SRT) that I've imported using the pt_ImportSubtitles script. It imports a single text layer with key frames animating the text along with the voice over. It also puts a layer marker at each key frame.



I've been tasked with a branded subtitle graphic template where by the client can import an srt file and the textbox around the text will automatically resize to the text as it animates (by animating I mean jumps from text line to text line via hold keyframes). There is a text box and a circle in the top left corner of it.



Here's what I'd like to do:

1) The circle - It's precomped and a scale up and down animation is inside it. I get the approach of triggering on a marker with a comment but I can't take that approach here because as a template the comment will never be the same. So I'd like to trigger the In animation on the first marker on the text layer without having to reference its comment. The out animation I'd like to trigger on the last key frame on the text layer. I can't use the last marker because the importsubtitles script doesn't create a marker on the last key frame. I'd rather not have to ask the client to set a marker every time they use the template. I'm familiar with using basic if/else statements but I have no idea how to access the first marker with no comment and the last keyframe or how to combine that into one if/else statement. Or if that's even the right approach.

2) The text box - no animation on this. I just want the opacity for the box at 0% when there is no text and 100% when there is. Currently, If there is no text, for example before the VO starts, the box stays on screen like this:



and I'd rather not have it visible.

Any help on this code would be extremely helpful.
Thank you!


Return to posts index

Eric Shepherd
Re: If/Else Statement - Triggering Animation on First Marker and on Last Keyframe
on Mar 2, 2020 at 4:58:59 pm

Ok, after some if/else statement poking around I found the solution for 2, getting the boxes to disappear when there's no text:
if (thisComp.layer(1)("Text")("Source Text") == "") {
0
}else{
100
}


Return to posts index

Tomas Bumbulevičius
Re: If/Else Statement - Triggering Animation on First Marker and on Last Keyframe
on Mar 4, 2020 at 8:56:23 am

Hey Eric, to break down your 1st issue:

1. Do you want to control scale-up and scale-down as time-remapping? Meaning, is animation of scaling defined in the pre-comp, or outside of it?
2. So animation in, should start at 1st market. Animation out - on last keyframe on text source. Is this correct? Maybe it would make more sense to also do delays for both?

Covering these questions will lay a ground for solution.

Find out more:
After Effects Tutorials: motion design, expressions, scripting.
Boxer - Dynamic Text Boxes Template with a Live Preview


Return to posts index


Eric Shepherd
Re: If/Else Statement - Triggering Animation on First Marker and on Last Keyframe
on Mar 9, 2020 at 3:53:31 pm

Hi Tomas,

1. Yes, Ideally I'd like to control the scaling animation from within a pre-comp and time-remap it.
2. Correct, Animation In on first marker, Animation out at last keyframe. I've been plugging away at the animation in code and I'm a bit stuck. So far I've got:


m = thisComp.layer(1).marker.key(1);
animationDurationInFrames = 10;
frameRate = 23.976;
animationDurationSeconds = animationDurationInFrames/frameRate;
mTime = m.time;
animStart = mTime-animationDurationSeconds;


if (time >= mTime) {
animationDurationSeconds
}else if(time <= animStart){
0
}else{
time-animStart
}


At this point the circle just pops on at the first marker. I can't get it to animate on at the marker. As for triggering the out animation on the last key frame, I'm guessing I'd use numKeys? But I have no idea how I'd get it to return the last keyframe on a given layer.

Eric


Return to posts index

Tomas Bumbulevičius
Re: If/Else Statement - Triggering Animation on First Marker and on Last Keyframe
on Mar 10, 2020 at 6:01:09 pm

Eric, try below, it seems like it should be it. Alternatively, please just provide a draft .aep to work on directly.

You could adjust timings easily by linking slider to values. Of course, if this is what you are after !

m = thisComp.layer(1).marker.key(1);

textLayer = thisComp.layer(1).text.sourceText;
textLastKey = textLayer.key(textLayer.numKeys);
textLastKeyTime = textLastKey.time;

animationDurationInFrames = 10;
frameDur = thisComp.frameDuration;
animationDurationSeconds = animationDurationInFrames * frameDur;
mTime = m.time;
animStart = mTime-animationDurationSeconds;

eTime = textLastKeyTime+animationDurationSeconds;


if (time &lt;= mTime){
s = ease(time, animStart, mTime, 0, 100);
}else if (time >= textLastKeyTime){
s = ease(time, textLastKeyTime, eTime, 100, 0)
}else{
s = 100;
}

[s,s]


Find out more:
After Effects Tutorials: motion design, expressions, scripting.
Boxer - Dynamic Text Boxes Template with a Live Preview


Return to posts index

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