Download Project File

Minimum & Maximum Method in After Effects

In this post, you will learn about the Minimum and Maximum Method in After Effects. So without any further ado, let’s dive right!

Alright, so we are in After Effects. First, let me show you what we are going to be creating in this post. As you can see in the picture below, I have two columns along with an orange line that has a number next to it.

Two columns in After Effects

Now watch what happens when I push the blue column forward past the green column.

Pushing the orange line forward in After Effects

As you can see, when the blue column becomes bigger than the green column, the blue column takes over the orange line and push it forward.

When the blue column becomes smaller than the green column, the green column takes over the orange line.

Green column takes the orange line in After Effects

The same thing applies to the green column.

We also have a very useful option called MIN/MAX SWAP. It allows us to swap from minimum to maximum and vice versa.

In this example, if we check the MIN/MAX SWAP checkbox, it will take the lowest value instead of the highest value for our orange line.

Mix max swap in After Effects

So as soon as the blue column becomes bigger than the green column, it will stay with the green column.

Swap Minimum and Maximum in After Effects

I am going to show you how to set this up but I will not show you how to create everything in this tutorial from scratch. That’s when the project file comes in handy. Make sure to download it to follow along. So let’s get to it!

The first thing I am going to do is select the orange line and hit P on my keyboard to reveal the position property.

Select the orange line in After Effects

As you can see, the orange line position has an expression already because the position numbers are red.

Position has an expression in After Effects

Which means I cannot grab the orange line. In other words, the orange line position is locked. Let’s change that!

I am going to get rid of this lock by holding ALT+CLICK (OPT+CLICK on a Mac) on the orange line position stopwatch icon.

Alt left click on stopwatch icon keyboard shortcut in After Effects

Now the restriction is gone and the numbers changed from red to blue. I can now freely move the orange line around anywhere I want to.

Freely moving the orange line around in After Effects

As you can see from the picture above, the text also moves with my line because it is parented to the orange line.

Number is parented to orange line in After Effects

Next, I am going to ALT+CLICK (OPT+CLICK on a Mac) on the stopwatch icon and I am going to set some variables in the white text box.

Alt click on the stopwatch icon in After Effects

Inside of the white text box I will say swap = and then I will pick-whip to MIN/MAX SWAP checkbox.

swap = thisComp.layer(“CONTROLS”).effect(“MIN/MAX SWAP”)(“Checkbox”);

Pick whip to min max swap checkbox in After Effects

Then I will say columnA = you’re going to be and then I will pick-whip to COLUMN A WIDTH Slider.

swap = thisComp.layer(“CONTROLS”).effect(“MIN/MAX SWAP”)(“Checkbox”);

columnA = thisComp.layer(“CONTROLS”).effect(“COLUMN A WIDTH”)(“Slider”);

Column A width slider pick whip in After Effects

Column A width slide After Effects

And then we will say columnB, you’re going to be and then I will pick-whip to COLUMN B WIDTH Slider.

swap = thisComp.layer(“CONTROLS”).effect(“MIN/MAX SWAP”)(“Checkbox”);

columnA = thisComp.layer(“CONTROLS”).effect(“COLUMN A WIDTH”)(“Slider”);

columnB = thisComp.layer(“CONTROLS”).effect(“COLUMN B WIDTH”)(“Slider”);

So now we have our variables. Next, let’s do our expression. So I am going to say x = you’re going to be Math.max().

Math max expression in After Effects

Basically, whatever I enter inside of Math.max() parenthesis is going to give me the highest number. If I put 5 numbers inside of the Math.max() parenthesis, then it will give me the highest number of those five numbers.

 

With that said, I want the highest number between columnA and columnB. So inside of Math.max() I will say Math.max(columnA, columnB);. 

ColumnA ColumnB Math max After Effects

Basically, I am saying give me the highest number between those two columns.

For the y, I am just going to say grab the current value. So I am going to say y = value[1];

X value in After Effects

Then I will say x be x and y be y like so: [x, y];

swap = thisComp.layer(“CONTROLS”).effect(“MIN/MAX SWAP”)(“Checkbox”);

columnA = thisComp.layer(“CONTROLS”).effect(“COLUMN A WIDTH”)(“Slider”);

columnB = thisComp.layer(“CONTROLS”).effect(“COLUMN B WIDTH”)(“Slider”);

 

Math.max(columnA, columnB);

x = value[1];

[x, y];

And there you have it! It is working perfectly! As you can see, the orange line will automatically go with the longest column.

Line is extending with the longest column in After Effects

Now we need to set up to where the orange line stays with the lowest number instead of the highest.

All we need to do is change the Math.max(columnA, columnB); to Math.min(columnA, columnB);


You can see that the orange line snaps to the minimal number, which is currently the blue column.

Snaps to minimum in After Effects

However, if move the blue column past the green column, the orange line will automatically snap to the green column instead.

Snaps to minumum green column in After Effects

Next, I will show you how to set up the MIN/MAX SWAP switch. So when I check the MIN/MAX SWAP checkbox, it will switch to minimum and when I uncheck it, it will switch to maximum.

To do that, we just need to add a simple if/else statement to our expression like so:

swap = thisComp.layer(“CONTROLS”).effect(“MIN/MAX SWAP”)(“Checkbox”);

columnA = thisComp.layer(“CONTROLS”).effect(“COLUMN A WIDTH”)(“Slider”);

columnB = thisComp.layer(“CONTROLS”).effect(“COLUMN B WIDTH”)(“Slider”);

 

if(swap == true){Math.min(columnA, columnB)} else {Math.max(columnA, columnB}

x = value[1];

[x, y];

If else statement in After Effects

So what that if/else statement is saying is that if the swap checkbox is checked, then it will run the Math.min(columnA, columnB) expression, and if not, it will run the Math.max(columnA, columnB) instead. That simple! The checkbox should now be working correctly flawlessly!

I hope you found this post useful. If you would like to learn more about Expression and how it can speed up your workflow in After Effects, check out my Learn After Effects Expressions Course.

Download Project File

About the author:

Sergei Prokhnevskiy

Sergei Prokhnevskiy is a Charlotte, NC based motion graphics designer, an online tutor, an entrepreneur, and Adobe MAX Master Speaker. Sergei is known for his quick and practical After Effects tips and tricks on YouTube, where he generated well over 6 million views on his tutorials. He has authored an online video course on After Effects Expressions and developed scripts for After Effects. He is also a former senior motion graphics designer at Fox Sports where he worked on graphics for NFL, Super Bowl, MLB, World Series, College Football, NASCAR, Women’s World Cup, and NASCAR Race Hub. He is very passionate about learning and teaching others.

5 FREE TIME-SAVING TOOLS

Over 100,000 downloads & counting!

These 5 After Effects tools will seriously speed up your workflow and save you hours of wasted time. More than that, they could be the difference between being able to complete a project on time or not!