Skip to content
solomotion
MakeScripts and expressions

Write motion as code

Keep a label 120 px above a moving card, make a shape pulse with the bass, or build forty layers with one script.

The Scripts panel open beside the stage, with a script in the editor, a Run button at the top and an Output area with a command prompt below.
  1. Select a layer and pick the property to drive.
  2. Open its expression editor and write a formula. It is evaluated every frame.
  3. Read another layer by name: layer("Card").y - 120 keeps a label 120 px above a card that animates.
  4. Remove the expression to restore the property's own keys underneath.

#value is the property's own keys or base value. #value + wiggle(2, 5) shakes your animation instead of replacing it. #time is the playhead, so sin(#time * 2) * 20 loops and #time * 90 spins at a constant rate.

Other functions include random, noise, wiggle, clamp, mix, map, smoothstep, blink, rgb, hsl and if.

Read bones, sound and trackers

Expressions reach into other systems by name.

  1. Move a rig control and read it: bone("Face", "Mouth", "y") returns that bone's pose. Wire it to a switch with map(...).
  2. Blink on top of keyed eyes: if(blink(4) > 0, "Closed", #value). One expression shared by both eyes blinks them together.
  3. Pulse with music: 1 + 0.25 * sound("Music", "bass").
  4. Follow footage: track("Face").position + vec(0, -120) puts a caption above a head.
  5. Jaw from a voice: loudness("Voice") returns 0 to 1.
  6. Read a component's input with input("Mood"), and a state machine's current state with state("Mood").

Run a script

  1. Open the Scripts panel.
  2. Choose New script, and write JavaScript. The file is the body of an async function. ac is the API, here is the comp you are on, and return shows a value in Output.
  3. Press the run button. A run is one undo step.

Every tool an agent uses is also an ac call. layer_create becomes await ac.layer.create({...}). Await every call, or the next line reads stale state.

word-stack.js
const WORDS = ["Design", "in", "motion"];
const GAP = 140;
for (const [i, word] of WORDS.entries()) {
  await ac.layer.create({
    kind: "text",
    text: word,
    y: (i - (WORDS.length - 1) / 2) * GAP,
  });
}

Position from here.width and here.height so the script works in any comp.

A saved script re-runs in Replace mode by default. Each run removes what the last run created, then rebuilds. Choose Append to add on every run. Set values rather than increment them, because a re-run applies the code again.

Turn a layer into code

  1. Right-click a layer and choose Copy as code, or choose New script from selection.
  2. The result is the script that rebuilds those layers. Edit a colour, a timing, or loop the creation over data.
  3. Run it in Replace mode. The first run swaps the originals for the code's rebuild, in the same stack position.

Ask an agent

Agents write formulas with expression_set and list every function with expression_reference. They run code with script_run, save it with script_save, and read it back with script_read and script_list. script_reify prints layers, a comp or a state machine as code. Long runs go in the background and are watched with script_runs, script_logs and script_stop.

Text
Reify the hero title as a script, then change its timing so each word enters 80 ms after the last.