cadcode
CAD for people who write code: a part as a JavaScript module, a live preview on every save, an STL for the slicer.
cadcode is CAD for people who already write code. You describe a part as a JavaScript module, watch it rebuild in the browser every time you save, and send the STL to your slicer. If you own a 3D printer and know JavaScript, a bracket should not cost you a week of learning where the menus are.
The part is a function. It takes its sizes and returns a solid:
import { cube } from 'cadcode';
export const params = { width: 60, depth: 40, height: 25, wall: 2 };
export default (p) =>
cube([p.width, p.depth, p.height]).subtract(
cube([p.width - 2 * p.wall, p.depth - 2 * p.wall, p.height]).translate([p.wall, p.wall, p.wall]),
);
Everything a programmer already has comes with it for free. Variables instead of dimension dialogs, loops instead of pattern tools, a function instead of a copied sketch. A model is a text file, so it lives in git: you diff it, branch it, and revert the commit that broke the fit. It can import its own helpers and any npm package, and TypeScript works too.
A variant is a flag, not a redraw. Sizes live in params, and cadcode stl box.js --set width=80 prints the wider one. --set only accepts what the program declared — so a typo stops the export instead of quietly printing the default:
cadcode: Unknown parameter "widht". Declared: width, depth, height, wall
A program can also export named parts — assembly, box, lid, print — and the CLI exports one, or all of them, a file each.
cadcode dev is where the time actually goes. It watches the program and every file it imports, rebuilds on save, and swaps the model into the page without touching the camera: you keep your angle and zoom while you iterate, and the view is remembered per file across restarts. An error shows up with the line in your file, and the last good model stays on screen until you fix it. Params get a panel — drag a number’s name sideways to scrub it. And the same render runs without a browser: cadcode png has its own small software rasterizer, so a preview sheet comes out of CI, or out of an agent checking its own work. The package ships a skill for exactly that.
The geometry runs on manifold, the boolean engine recent OpenSCAD uses. That is the whole reason the STL is always watertight: no non-manifold edges, no slicer repairing your mesh behind your back.
Coming from OpenSCAD, nothing is new. cube, cylinder, hull, difference, $fn are all there, and a model ports line by line. The one thing to retrain is the reading order: OpenSCAD’s translate(t) rotate(r) child becomes child.rotate(r).translate(t) — transforms read from the inside out.
There is a playground with 32 examples to open and edit, from a hinged box that prints already assembled and open flat to a chess set.
Node 20 or newer, MIT: npm install cadcode.