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.
Now watch what happens when I push the blue column forward past the green column.
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.
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.
So as soon as the blue column becomes bigger than the green column, it will stay with the green column.
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.
As you can see, the orange line position has an expression already because the position numbers are red.
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.
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.
As you can see from the picture above, the text also moves with my line because it is parented to the orange line.
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.
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”);
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”);
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().
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);.
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];
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.
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.
However, if move the blue column past the green column, the orange line will automatically snap to the green column instead.
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];
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.