lmcad script authoring skill
Purpose
Help write valid, useful lmscript programs for lmcad and verify their geometry, renders and exports.
When to use it
Use this skill when a task needs a parametric solid, a checked volume, a still render, an STL or OBJ export, a looped field of parts, or a keyframed APNG, all without a GPU or display.
Install
Install the published lmscript package; a block that names install="github:lmctl-ai/lmcad@latest" makes lmscript download the released lmcad for Linux x64 or Linux arm64. Binaries are also on the Releases page. Confirm the host prints lmcad X.Y.Z with --version and emits its schema with --lmcode-schema --json.
npm install -g @lmctl-ai/lmctl
Commands
lmscript --check model.lms
lmscript model.lms
lmctl autorun https://raw.githubusercontent.com/lmctl-ai/lmcad/main/examples/box-volume.lms
lmcad --version
lmcad --lmcode-schema
lmcad --lmcode-schema --json
lmcad --lmcode-signatures
lmcad --lmcode FILE [FILE ...]
Write the block as p = _lmcode_ cli="lmcad" install="github:lmctl-ai/lmcad@latest"; ... end _lmcode_ and execute it with r = run_lmcode(p). The --lmcode flags are the host protocol that lmscript drives; running saved bytecode by hand is only needed for reruns.
Inputs and outputs
- Input is an lmscript file with one or more _lmcode_ blocks, plus optional CSV keyframes read by read_keyframes_csv.
- Each block is compiled against the schema the lmcad binary reports and run by that binary; run_lmcode returns a result with ok and result.
- Outputs are PNG, PPM, APNG, binary STL and text OBJ files. Volumes and bounding-box coordinates are available inside the block.
- lmcad 0.1.5 ships 206 standard-library signatures (the lmcode_std_v3 catalog at 206). The current lmcode_std_v3 catalog has 226 signatures, adding the REST and CLI interfaces; lmcad picks those up when it syncs and releases, and the 0.1.5 binary does not register them.
Safety rules
- Use finite positive dimensions and stay inside the host limits: sketch coordinates within ±500 units, part extent 1000, 240 animation frames, 64,000,000 total frame pixels.
- Treat scripts as trusted input: the VM has no run-time execution budget.
- Outer lmscript variables are not visible inside a block.
- Use unique local names; host function names, the scene context and type names are reserved.
- Cast integer loop indices with float(i) before passing them to float parameters.
- Always call finish() on an animation; an unfinished animation is discarded.
- Do not call the REST or CLI standard interfaces; this release does not register them.
Worked examples
A complete program from the repository examples (box-volume.lms):
mkdir("images");
p = _lmcode_ cli="lmcad" install="github:lmctl-ai/lmcad@latest";
let shape = scene.box(2.0, 3.0, 4.0, material().color(0.2, 0.55, 0.85));
scene.assert_close(shape.volume(), 24.0, 0.000001);
scene.fit_camera(42.0, 1.2);
scene.directional_light(-0.5, -1.0, -0.4, 0.8);
scene.ambient(0.2);
scene.render_png("images/box-volume.png", 320, 240);
end _lmcode_
r = run_lmcode(p);
if (!r.ok) { println(r.stderr + r.stdout); }
assert(r.ok);
println("wrote images/box-volume.png");
- Primitive: scene.box(x, y, z, material()), scene.sphere(radius, material()), scene.cylinder(radius, height, material()) or scene.tube_between for a segment between two points.
- Boolean and edge treatment: base.cut(tool), a.union(b), a.intersect(b), shape.fillet(radius), then inspect shape.volume().
- Sketch feature: chain scene.sketch().point(x, y), call close(), then scene.extrude(sketch, height, material()) or scene.revolve_y(sketch, material()).
- Camera and lighting: scene.fit_camera(42.0, 1.2), directional_light, fill_light and ambient.
- Loops: for (i in range(0, n)) places repeated solids.
- Animation: load keyframes with read_keyframes_csv(path), interpolate, then call add_frame() per frame and finish().
Errors and exit codes
| Exit code | Meaning |
|---|---|
| 0 | Success; one JSON result line per completed block. |
| 2 | Invalid command line. The host prints its usage line and a CLI_USAGE result (phase cli). |
| 3 | Program file load failure or a block or host run failure. |
| 4 | Another application failure. |
When run_lmcode returns ok false, print r.stderr and r.stdout as the repository examples do. A common compile error is passing an integer where a float is required. Common run errors are an OCCT fillet or shell that is too large, a render without a camera, and a failed assert_close.
How to verify
- Run lmscript --check on the file to compile every block against the lmcad schema.
- Run the file and assert r.ok.
- Put shape.volume() and scene.assert_close in the block so a wrong model fails instead of rendering.
- Check that the expected PNG, APNG, STL or OBJ files exist and view the PNG for silhouette, lighting and background.
- Compare lmcad --lmcode-signatures with lmscript --lmcode-signatures on the schema JSON when a host and compiler mismatch is suspected.