extrudo

Docs

Macros

emitScript(doc) turns a design back into the TypeScript that makes it. Every feature becomes the call the API takes for it — the same methods Features lists — with its stored inputs, its references as handle expressions and its sketches as d.sketch(plane, (k) => { … }). The document already is the record of what was built (ADR-0003), so a macro is not a log of clicks: it is the inverse of the API (ADR-0073).

The code runs against a Design or, as printed, inside a Script feature, which is why its design variable is design. Nothing new is stored; the function is pure.

import { Design, emitScript } from '@extrudo/api';

const d = Design.create({ name: 'Plate' });
d.parameter('width', '80 mm');
const s = d.sketch(d.origin.xy, (k) => {
  const plate = k.rectangle([0, 0], [40, 20]);
  k.dimension(plate.bottom, '40 mm', { name: 'width' });
});
d.extrude({ profiles: s.profileAt([5, 5]), distance: '10 mm' });

console.log(emitScript(d.toJSON()));

The output is a program, not data:

design.parameter('width', '80 mm');
const sketch1 = design.sketch(design.origin.xy, (k) => {
  const l1 = k.line([0, 0], [40, 0]);
  // … three more lines and their constraints …
  k.dimension(l1, '40 mm', { name: 'width' });
});
const extrude1 = design.extrude({
  profiles: [sketch1.profileAt([5, 5])],
  distance: '10 mm',
});

A run of the timeline

options.features selects a contiguous run, as [from, to] feature indices or IDs. A reference to a feature before the run stays the stored name (it is already in the design the run is added to); a reference inside the run becomes a handle. The design's own parameters are left out of a run by default — the design it runs in already has them.

import { Design, emitScript } from '@extrudo/api';

const d = Design.create();
const first = d.box({ length: '10 mm', width: '10 mm', height: '10 mm' });
const edge = first.edge([first.faceName('cap:end'), first.faceName('side:front')]);
d.fillet({ edges: edge, radius: '1 mm' });

const run = emitScript(d.toJSON(), { features: [1, 1] });
console.log(run);

What is preserved

In the CLI

extrudo script <design.extrudo> prints the same code, with --features a..b for one run and --param/--config to emit a changed design. See the CLI guide.