Quickly create complex layer arrays in After Effects with the index expression. Instead of wasting time tweaking the properties of individual duplicate layers, you can completely automate each new layer to change using this expression.
Say you want to duplicate a layer, with each new layer offset by a certain rotation, to create something like a simple flower. Normally, this would require painstakingly clicking each layer and adjusting its rotation one by one.
Below: Manually rotating each new layer.
With the index expression applied correctly, each new duplicate of your layer will automatically rotate for you. As you can see, this method is much more efficient.
Below: Duplicating layers using the index expression.
Now that you understand the usefulness of the index expression in everyday situations, let’s take a look at how to apply it.
What Does “Index” Mean?
The index expression refers to a layer’s assigned number within a composition. For instance, the very topmost layer would have an index of 1, with the layer below it having an index of 2, and so on.
By default, After Effects displays the Layer Number to the left of the Layer Name. If for some reason it isn’t visible, you can enable it by right-clicking one of the composition columns, and enabling the “#” column.
How To Use the Index Expression
In most cases, you will start with the expression (Index-1). This will establish a change each time the layer is duplicated. Say you were to apply (Index-1) to the rotation property of a layer. This would cause each new layer to rotate 1 degree further than the previous.
You can increase the amount of rotation by multiplying your index value, or you can decrease it by dividing. For example, (Index-1)*30 would increase each new layer’s rotation by 30 degrees, whereas (Index-1)/30 would increase each new layer’s rotation by 1/30th of a degree.
You’ll soon realize that using some basic mathematical logic, you can apply the index expression in a variety of creative ways to speed up your workflow.
Applying To Multi-Dimensional Properties
One-dimensional properties like rotation are fairly straightforward, but using this expression with two-dimensional and three-dimensional properties such as scale and position is slightly more complex. Let’s use the scale properties of a 2D layer, which are Width (X-axis) and Height (Y-axis), as an example. Defining your X and Y properties would look like this:
Value is the X-value, and value is the Y-value. Here is an example with real scale values:
This would set the layer’s scale to 50% width and 100% height. With numeric values, you don’t have to include the  or  designation. If these designations are referenced within a variable, you won’t need to specify them in the final value brackets either.
Uniform 2D Properties
To increase overall scale by, say, 10% each duplication, you would need to apply the same expression to both of these scale axes. Replacing key expressions with variables can better organize the final code as well. Here are examples both with and without variables.
x = (index-1)*10;
Below: When applied to scale, this expression will increase each new layer’s scale by 10%.
As you can see, in the Variable Example we established our index expression as “x” in the first line, and were able to apply it to both the width and height of the layer in the second line. This can clean up your expression and save you some time copying and pasting segments of code.
Non-Uniform 2D Properties
If you only want to affect the height (Y-axis) of your layer, your expression would look like this:
b = (index-1)*10;
Value represents the current scale input value for width. In other words, if you were to enter the expression [value, value], your layer would not be affected at all.
If your layer’s current scale is 13% width, and 37% height, then value would equal 13 and value would equal 37. Value expressions show whatever the current value is, and will change according to keyframes as well.
The properties of 3D layers work under the same logic as 2D layer properties. For instance, the expression for input scale on a 2D object would be [value, value] whereas the expression for a 3D object would look like [value, value, value].
The designation  refers to the X-axis, while  refers to the Y-axis and  refers to the Z-axis. Therefore, you would replace any of the axes you want to modify with your expression, or its assigned variable.
Increasing the position of all axes by 200 pixels would be achieved with this expression:
x = value + (index-1)*200;
[x, x, x];
You can even apply a different expression to each axis.
a = value + (index-1)*200;
b = value + (index-1)*400;
c = value + (index-1)*600;
[a, b, c];
If you want a layer’s property to decrease with each copy instead of increase, you’ll just need to add one more simple line to your expression. To decrease a layer’s rotation by 5 degrees each duplicate, your expression would look like this:
x = (index-1)*5;
value – x;
This takes the resulting value of your Index expression (which here is defined as X), and subtracts it from the current property value of your first layer.
Setting Start Values
The below expression would increase your property as normal, but would allow you to adjust the starting point for your first layer.
x = (index-1)*5;
value + x;
If the expression did not include the secondary line, your first layer would start with your Index Value by default. What this means is if the layer is #8, your expression would be the result of (8-1)*5, which is 35.
value + x; adds the value of “x” to the property’s original value, instead of replacing that value.
The “-1” in (Index-1) is included to reduce the Index Value of your first layer to 0, so that 0 is your starting value instead of 1. If your layer is #7, changing your expression to (Index-7) would ensure your Index Value within the expression starts at 0. Conversely, you could change it to (Index+7) and your Index Value would start at 14.
You can use this expression on multiple properties of the same layer, so that your layer perhaps doubles in size and rotates 90 degrees each duplication, or maybe moves 500 horizontal pixels and decreases opacity by 10% each time.
You can even apply this to effect properties, like the Colorize Hue Angle Control of the Hue/Saturation effect, which would offset the color of each new layer.
You can get mathematically creative as well – for instance, you can multiple an index phrase by itself to create an exponential increase or decrease of a layer property.
While the math inherently involved in using this expression might be discouraging at first, you’ll quickly come to appreciate the time it saves you in the future.
What cool ways have you applied this expression? Let us know in the comments below.