Create a new empty comp and add a new layer. Then apply this expression to its Position property:
Now as you duplicate the layer multiple times you will see how all layers automatically adjust their x position to create an evenly spaced row.
Congratulations, you're a wizard Harry. Now let's break it down:
We divide the current index of the layer with the number of layers of the comp. Notice though that we bumped the number of layers up by one.
That's because we want to keep things centered. The minimum index of a layer is 1. When we divide 1 by 2, we get 0.5, which is exactly half.
This scales up as we add more layers.
You can try omitting the one and see what happens.
Anyway, after having a number between 0 and 1, we multiply it by the comp width:
And finally, we assign it to a variable named x, and use the original y value from the property.
Let's add some colors
I have cleared the comp and copied the Position expression we wrote above, but this time to a shape layer with a fill.
Now let's apply the following expression to the fill:
Now duplicate the layer again and look at that:
We are using the same technique of dividing the current index by the number of layers in this comp to get a value between 0 and 1.
Once we have that value, we can use the linear() function to blend between our two arrays of colors progressively. How cool is that?
These kinds of rigging examples using the numLayers property work best in isolated comps. If you were to add any extra layer to the comp we just built in the example above, you might screw up your entire logic.
However, used correctly numLayers can be pretty powerful and allow you to create some magical procedural systems that are easy to change and modify later on.