Skip to content
Raisul Sohan

Building from source#

How the panel is put together, the one rule every tool follows, the five test layers, and the After Effects behaviours that cost a day each to find. Written for LazyMotionToolkit 1.12.

Contents

  1. The shape of the repository
  2. One file, twelve sections
  3. The engine-and-wrapper rule
  4. The test layers
  5. After Effects traps worth knowing
  6. House style
  7. Redoing the pictures in docs/
  8. Cutting a release

1. The shape of the repository#

LazyMotionToolkit.jsx     the whole panel — this is what ships
CHANGELOG.md              every version
README.md                 the tour
assets/                   logo, banner, demo gif and mp4
docs/                     these pages
tools/                    development only; users never need it
  check-extendscript.js     ES3 parse + lint, under Windows Script Host
  test-toolkit.js           the engines against a mocked After Effects
  ae-smoke-test.jsx         the engines inside the real After Effects
  ae-autobox-test.jsx       the Auto Box rig, in the real After Effects
  ae-headline-test.jsx      Head to Line, in the real After Effects
  ae-ui-test-panel.jsx      builds the real panel (needs the UI)
  ae-ui-test-audio.jsx      LazyStrike Audio-Driven (needs the UI)
  ae-autobox-perf.jsx       times the box rig (a probe, not pass/fail)
  ae-autobox-unicode.jsx    types Bengali on and watches the box (a probe)
  ae-headline-render.jsx    draws every arrowhead to a PNG (a probe)
  ae-docs-shots.jsx         renders the pictures for docs/images
  ae-docs-panel.jsx         opens one window so it can be photographed
  docs-shots.ps1            drives After Effects and takes the screenshots
  capture-window.ps1        saves one window to a PNG, by title
  package-release.mjs       builds the release zip
  render-banner.mjs         renders assets/banner.svg to banner.png
  zip.mjs                   a tiny zip writer, no dependencies
  installer/                the .bat and .command files that go in the zip

There is no build step and no dependency. LazyMotionToolkit.jsx is the program; everything else is scaffolding.


2. One file, twelve sections#

The panel is a single IIFE. Numbered section banners divide it:

Section What lives there
1 Color Helper Utilities hex ↔ After Effects colour arrays
2 Swatch State & Persistence the palette, and reading/writing app.settings
3 Smart Precomp Engines both precomps, mask bounds, crop maths
4 Auto Text Box Maker the LazyType rig — see How Auto Box works
5 Fade Tools Pro the seven easing functions and the fade expression
6 Head to Line Engine head shapes, path following
7 9-Point Anchor Point Aligner anchor moves and their position compensation
8 Stagger & Null Parent time offsets, keyframe shifting, the null rig
9 Grid Designer Dialog grid maths and its guard rails
10 LazyStrike FX lightning, flashes, audio peaks
11 LazyPreview Render the aerender job, the preview layer, file clean-up
12 Main ScriptUI Window the panel, its theme and every dialog

The file ends with a test hook. When $.global.LazyMotionToolkitTest is set before the script is loaded, it fills that object with about 70 engine functions and returns null instead of building a panel:

$.global.LazyMotionToolkitTest = {};
$.evalFile(new File("…/LazyMotionToolkit.jsx"));
var api = $.global.LazyMotionToolkitTest.api;
api.autoBoxLayers(comp, [textLayer], {});

It is never set in normal use.


3. The engine-and-wrapper rule#

Every tool is split in two. An engine takes what it works on as arguments and returns what it did:

function staggerLayers(comp, layers, frames, reverse, keysOnly) { … }

and a thin wrapper does the guards, reads the selection and reports:

function executeStagger(frames, reverse, keysOnly) {
    var comp = app.project.activeItem;
    if (!comp || !(comp instanceof CompItem)) { alert("Please open a composition first."); return; }
    …
    reportSkipped("Stagger", staggerLayers(comp, selected, frames, reverse, keysOnly).skipped);
}

This is not tidiness. A headless After Effects has no selection and no activeItem: comp.selectedLayers comes back empty even after setting layer.selected = true. A tool that reads the selection itself cannot be tested at all. Head to Line was the last one written the other way, and it is exactly the tool that shipped with a head that never rotated, for four versions, because nothing could drive it. It was split in 1.11.

Engines return { made, skipped } or similar, never alert(). Skipped entries carry the reason in brackets: "Logo (locked)". Wrappers do all the talking.


4. The test layers#

Run all of these before calling a change good. Windows commands shown; the path to AfterFX.com will differ by version.

Command What it checks
cscript //Nologo tools\check-extendscript.js Every .jsx compiles as ES3, and avoids what real ExtendScript rejects but JScript accepts.
cscript //Nologo tools\test-toolkit.js 179 tests of the engines against a mocked After Effects: precompose choices, mask bounds and cropping, fade expressions evaluated frame by frame, anchor maths, colours, grid limits, lightning schedules, audio peaks, the aerender command line and preview clean-up.
AfterFX.com -noui -r tools\ae-smoke-test.jsx The same behaviour inside the real After Effects, with pixel placement measured by After Effects' own expression engine — plus Stagger, Null + Parent, and a real aerender preview render from a folder with Bengali letters, including Cancel.
AfterFX.com -noui -r tools\ae-autobox-test.jsx The Auto Box rig on real text: the box on the text to the pixel for all six styles, no expression left disabled, re-running replacing instead of stacking, two layers each measuring their own text, the caret tracking.
AfterFX.com -noui -r tools\ae-headline-test.jsx Head to Line: the head on the end of a straight line and a turning one, both ends, Trim Paths, all eight shapes read back from the polystar, the replace-on-second-click behaviour, an orphaned head.
AfterFX.com -r tools\ae-ui-test-panel.jsx Builds the real panel and the LazyStrike window. No -noui — ScriptUI needs the UI.
AfterFX.com -r tools\ae-ui-test-audio.jsx LazyStrike Audio-Driven, which uses a menu command and so needs the UI: a generated WAV with two bursts must give two flashes, with the helper layer removed and the work area restored.

Each writes %TEMP%\lazymotion-*-results.txt (or lazystrike-audio-results.txt) and quits without saving. Close After Effects first, and turn on Allow Scripts to Write Files.

The three probes are not pass/fail — they print numbers or draw pictures: ae-autobox-perf.jsx times the box rig, ae-autobox-unicode.jsx types Bengali on and reports the measured widths, and ae-headline-render.jsx renders every arrowhead to a PNG.

Two things about running After Effects from the command line#

  • AfterFX.com returns before the script finishes. Reading the results file straight after the call can find nothing. Use Start-Process -Wait and then poll the file until it ends with a DONE line.
  • Firing -r at a still-running After Effects does nothing useful — the new instance hands its script to the old one. Check the process is gone first.

The rule the render probe exists for#

ae-headline-render.jsx was written after a test suite of 58 green checks missed an arrowhead that was drawing as a three-pointed star. The check was "does the head have some width and height", which a star passes as happily as a triangle.

Numbers are not enough for anything drawn. Render it with comp.saveFrameToPng and look at it. Put a real solid behind it — the comp background comes out transparent, and white on nothing looks like nothing.


5. After Effects traps worth knowing#

Each of these cost real time here. They are in the code as comments too.

An expression that throws is disabled for good. Not skipped for that frame — switched off permanently, and an undo does not bring it back. A bare thisLayer.parent read throws the moment a layer is unparented, so every one of them is wrapped:

var T = null; try { T = thisLayer.parent; } catch (e) { T = null; }

A 2D layer's rotation is ADBE Rotate Z. ADBE Rotation returns null, and setting .expression on null throws. Inside a broad try that throw is invisible — which is how an arrowhead that never rotated survived four releases.

Polystar properties are not where you would guess. Property 1 is ADBE Vector Shape Direction, not Type, so every by-index guess is off by one. Type 1 is a Star and 2 is a Polygon, the opposite way round from how it reads. The roundness match names are spelled ADBE Vector Star Inner Roundess and … Outer Roundess — one n, misspelled by Adobe. And switching Type to Polygon deletes any expression on Inner Radius, resets it to 50 and locks the property; switching back does not restore it.

Never fall back to a property number when a match name misses. Skip instead. Falling back writes into whatever property happens to sit at that index — which is how ticking "Round" ended up setting an inner radius.

A text layer's sourceRectAtTime never shrinks while it types on. Opacity and blur do not change it. That is the entire reason Auto Box builds a separate measure layer.

Adding or removing a layer invalidates layer references. Held objects go stale and throw ReferenceError: Object is invalid. Capture names or indices first, re-find afterwards, and work out the shift yourself when you know it (inserting one layer moves everything below it down by one).

app.newProject() is safe headless, app.project.close() is not — the latter ends the app. A previous headless run often leaves After Effects reopening a recovered untitled project, so the suites discard one when app.project.file is null and refuse only when a saved project is open.

An ES3 reserved word used as a name makes After Effects run nothing at all, in silence — var short = 1 is the classic. JScript accepts it, so a plain new Function(src) check will not catch it. check-extendscript.js lints for it.


6. House style#

  • ES3 only. No let, const, arrow functions, Array.prototype.indexOf, JSON, or trailing commas. The checker catches most of it.
  • ASCII in .jsx files. Non-ASCII goes in through String.fromCharCode(…) — see ae-autobox-unicode.jsx for Bengali strings.
  • Properties by match name, never by index, and never with a numeric fallback.
  • One undo group per user action, opened in the engine and closed in a finally.
  • Nothing fails silently. A layer that cannot be handled goes in skipped with a reason in brackets; a rig that half-built itself is removed, not left in the comp.
  • Comments explain why, not what — particularly the After Effects behaviours above, which look like mistakes until you know.

7. Redoing the pictures in docs/#

docs/images/ holds two kinds of picture, and they are made two different ways. Both need the UI, so close After Effects first.

What the tools make — auto-box.png and head-shapes.png — are real renders, from comps built by the engines themselves:

AfterFX.com -r toolsae-docs-shots.jsx

It writes them to %TEMP%lazymotion-doc-*.png; copy those into docs/images/. Each sheet gets a real dark solid at the bottom, because saveFrameToPng writes the comp background out transparent and white on nothing looks like nothing.

What the panel looks like — panel.png, auto-box-dialog.png, grid-dialog.png and lazystrike.png — are screenshots of the real thing:

powershell -ExecutionPolicy Bypass -File toolsdocs-shots.ps1

That starts its own After Effects, sends ae-docs-panel.jsx to it once per window, and captures each one with capture-window.ps1, which crops to the window's own rectangle and only ever looks at windows After Effects owns. The two modal dialogs block the script that opened them, so they are closed with Escape after the picture is taken. After Effects is closed at the end.

Two things that cost a few tries:

  • FindWindow with a null class name fails from PowerShell with error 123. capture-window.ps1 uses EnumWindows instead.
  • The panel cannot be widened for the photograph, and it is not worth trying. It pins each column pair to half its current width, so the content's preferred width always equals the width it already has: setting win.size is undone by the next layout pass, and win.layout.layout(true) snaps straight back. The screenshot is the panel at the width it chooses for itself, which is about what a docked column gets anyway.

The Auto Box dialog reopens with whatever was used last, which would contradict the defaults printed beside it in the manual, so the opener writes the defaults, shows the dialog, and puts the real settings back afterwards — they are the user's own After Effects preferences.


8. Cutting a release#

  1. Bump three things together: _buildVersion in the script, the **Version x** line in README.md, and a new ## x.y.z section in CHANGELOG.md. The packager refuses if they disagree.
  2. Run every check in section 4.
  3. node tools/package-release.mjs — it assembles the script, the installers from tools/installer/ and the licence into LazyMotionToolkit-v<version>.zip and puts it in the shared 00 Install from here folder beside the repository, removing the previous LazyMotionToolkit zip there. It prints the SHA-256.
  4. Commit, push, and create the GitHub release with that zip attached.

The version in the zip name drops a trailing .0, so 1.12.0 ships as LazyMotionToolkit-v1.12.zip and README.md must say Version 1.12.