# After Effects Expression - Align Elements on a Path

### Full step by step Tutorial:

{% embed url="<https://www.instagram.com/p/CC_TNoUnLL6/>" %}

Paste this code into the position property of the layers you can to align:

```javascript
let pathLayer = thisComp.layer("MAIN PATH");
let thePath = pathLayer.content("Shape 1").content("Path 1").path;
let sliderOffset = thisComp.layer("MAIN PATH").effect("OFFSET CONTROL")("Slider");
let offsetRepeat = sliderOffset % 100;
let offsetToAdd = linear(offsetRepeat, 0, 100, 1, 0);

let pathOffset = linear(index, 0, thisComp.numLayers-1, 0, 1);
let myPos = thePath.pointOnPath((pathOffset+offsetToAdd)%1, time);

seedRandom(index, true);
let posSlider = thisComp.layer("MAIN PATH").effect("RANDOM POSITION")("Slider");
let randomPos = random([-posSlider, -posSlider], [posSlider, posSlider]);

toComp(myPos) - thisComp.layer("MAIN PATH").transform.position + randomPos;


/*
Expression by Francisco Giordano, July 2020.
Free for personal use and commercial use.
Instagram @ae.fran.giodano - frangiordano96@gmail.com
*/
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://frangiordano96.gitbook.io/ae-expressions/quick-tips/after-effects-align-elements-on-a-path.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
