ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

# IF / ELSE scale expression

FAQ   •   VIEW ALL
 IF / ELSE scale expression on Aug 16, 2017 at 11:01:51 pm

Hello Guys!

I got two layers in a composition BARGRAPH and SHAPE10

I am making the BARGRAPH grow from 0% to 100% on the y-axis (scale) over different amounts of time.

As it grows, I want some shapes to pop-up on the screen when the scale reaches, on the y-axis ,for example 10%, 20%, 30%....

So, when the BARGRAPH y-scale reaches 10%, I want to link it to the SHAPE10 scale, so the SHAPE10 scale will grow from 0% to 100%. The movement needs to last something like half a second, so it will not just appear on the screen.

I know I need to apply on the SHAPE10 scale, something like this:

if(thisComp.layer("BARGRAPH").transform.scale[1]>10) 100 else 0;

But I know it is not right and I need to work on the dimensions, arrays and everything...

I have no idea how to make it work, i've been working with motion design for 5 years, but expressions are really hard for me.

 Re: IF / ELSE scale expressionon Aug 17, 2017 at 10:11:40 pm

you would need to have a way to determine what time the bargraph layer's y-scale hits 10%.

if you used 2 linear keyframes for the bargraph scale animation, you can calculate the time it would reach 10% (or any percentage)...

try this:
```target = thisComp.layer("BARGRAPH"); trigger = 10; // value in % minScale = 0; // value in % maxScale = 100; // value in % dur = .5; // value in seconds tStart = target.scale.key(1).time + ( trigger / 100 ) * ( target.scale.key(2).time - target.scale.key(1).time ); if ( target.scale[1] > trigger ) s = linear( time, tStart, tStart + dur, minScale, maxScale) else s = 0; [ s, s ]```
if you are using ease keyframes, it will be tougher....

Kevin Camp
Art Director
KCPQ, KZJO & KRCW

 Re: IF / ELSE scale expressionon Aug 18, 2017 at 2:45:03 pm

Thanks Kevin, but I think that will not work for me. ☹

I'm only working with 2 linear keyframes to make the y-scale go from 0% to 100%, but I think I can make it easier for you guys to help me.

I only need the SHAPE10 layer to appear on the screen when the BARGRAPH yscale reaches >10%.
I cant work with time or duration, because I need to apply this in many different comps with many different durations by just adjusting the linear keyframes.

I would like to adjust the linear keyframes on the BARGRAPH and make the SHAPE10 layer appear automatically when the yscale is more than 10% (and be able to apply it to other percentages and other layers).

 Re: IF / ELSE scale expressionon Aug 18, 2017 at 5:48:17 pm

If you want it to just appear when it goes above 10, your expression was fine. You just need to apply it to shape10 opacity.

if(thisComp.layer("BARGRAPH").transform.scale[1]>10) 100 else 0;

Otherwise I'm confused on what you are trying to do.

"I only need the SHAPE10 layer to appear on the screen when the BARGRAPH yscale reaches >10%."