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

Safety rules

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");
  1. 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.
  2. Boolean and edge treatment: base.cut(tool), a.union(b), a.intersect(b), shape.fillet(radius), then inspect shape.volume().
  3. Sketch feature: chain scene.sketch().point(x, y), call close(), then scene.extrude(sketch, height, material()) or scene.revolve_y(sketch, material()).
  4. Camera and lighting: scene.fit_camera(42.0, 1.2), directional_light, fill_light and ambient.
  5. Loops: for (i in range(0, n)) places repeated solids.
  6. Animation: load keyframes with read_keyframes_csv(path), interpolate, then call add_frame() per frame and finish().

Errors and exit codes

Exit codeMeaning
0Success; one JSON result line per completed block.
2Invalid command line. The host prints its usage line and a CLI_USAGE result (phase cli).
3Program file load failure or a block or host run failure.
4Another 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

  1. Run lmscript --check on the file to compile every block against the lmcad schema.
  2. Run the file and assert r.ok.
  3. Put shape.volume() and scene.assert_close in the block so a wrong model fails instead of rendering.
  4. Check that the expected PNG, APNG, STL or OBJ files exist and view the PNG for silhouette, lighting and background.
  5. Compare lmcad --lmcode-signatures with lmscript --lmcode-signatures on the schema JSON when a host and compiler mismatch is suspected.