Letting AI Design Your Enclosure: Parametric Boxes with OpenSCAD and Text-to-CAD

A box, reduced to its essentials, is a set of rectangles and cylinders derived from a handful of numbers. That makes it an ideal test case for AI-driven CAD. For this article I had an LLM generate a parametric PCB enclosure in OpenSCAD across three generations, reviewing each one line by line and recording what was right and what quietly broke. The conclusion is a clean division of labor — but the way the failures surfaced is the interesting part.
Why parametric code beats GUI modeling for boxes
Model a box in a GUI and the mounting-hole pitch ends up scattered across the file as four separate sketch dimensions. Swap in a different board and you must find and fix all four. Code-based CAD inverts this: dimensions live as named variables at the top of the file, and geometry is computed from them. Enclosure parameters split into two natural groups — measured facts (board size, hole pitch, protrusion heights, connector positions) and design decisions (wall thickness, clearance, boss margins). Keeping the two groups explicitly separate in the code means you know exactly which eight numbers to measure before you start, and which knobs are yours to turn.
Generation 1 — what one prompt gets you
The prompt: a two-piece PCB enclosure in OpenSCAD, board size, hole pitch, wall thickness, and clearance as top-of-file variables, bosses looped into the four corners, connector openings on the side. The generated code was structurally right — a bosses() module placing a boss at each corner with a for-loop over two sign variables replaces four hand-placed GUI holes, and the inside-out dimension flow matched good practice. But a line-by-line review found six problems, including bosses joined to the floor at a sharp right angle (the textbook stress riser), no chamfers on openings, and — the classic AI failure — a plausible-looking design that had never been checked against any real dimension.
Generation 2 — better, with subtler bugs
Feeding back the six points produced a second generation that fixed all of them and added genuinely correct structure: boss height derived from measured rear clearance plus a margin, self-tap pilot holes computed as screw diameter minus 0.25 mm, board height derived through a datum chain, and boss fillets approximated with a cone skirt. The new bugs were quieter. A chamfer specified as 0.5 mm actually varied between 0.25 and 0.43 mm depending on the edge, because it was computed from the wrong reference. And the code confused the clearance-hole diameter with the pilot-hole diameter while implementing the one-hole-diameter wall rule — right guideline, wrong variable.
Generation 3 — where the geometry finally broke
Generation 3 fixed those issues and added corner posts for lid screws. The code was the cleanest yet, with a coherent variable dependency graph. Then the numbers came out. For an 85 × 56 mm board with 0.5 mm clearance, the interior is 86 × 57 mm. The bosses (outer diameter 7.85 mm) sit on the 58 × 49 mm hole pitch; the lid posts (outer diameter 10 mm) sit one post-radius in from the inner wall, at (38, 23.5). Compute the distance from the nearest boss: center-to-center 9.055 mm against a radius sum of 8.925 mm — a gap of 0.130 mm. Mathematically separate; on a 0.4 mm nozzle, guaranteed to fuse into one lump. Worse, the posts span X 33–43 mm and Y 18.5–28.5 mm while the board itself extends to ±42.5 and ±28 — the posts stand inside the space the board occupies. Pushing them clear of the board means growing the interior from 86 × 57 to 106 × 77 mm, twenty millimeters in each direction.
None of this is visible by reading the code. It emerged from a five-line verification script that computes the boss-to-post distance and prints the margin. That is the repeatable lesson: turn the design rules in your head into small executable checks, because 0.130 mm is exactly the kind of number a human reviewer will never catch by eye.
Where Text-to-CAD fits
Dedicated Text-to-CAD systems differ from mesh generators in a fundamental way: they output B-Rep (boundary representation) solids, the native language of mechanical CAD. Ask one for a box that fits a Raspberry Pi 5 and a box will appear — but whether its hole pitch matches the official drawing is still your problem to verify. The tool class changes; the verification obligation does not.
The division of labor
Across three generations the pattern was consistent. AI is fast at writing form — modules, loops, parameter plumbing — and responsive to review: every flagged item was fixed by the next generation. What AI cannot supply is ground truth (it has never measured your board) and geometric verification (it does not check its own output against arithmetic). The human contribution is exactly those two things: supply measured dimensions, and run the checks. Three generations reached fillets, chamfers, datum-chained heights, and insert seats; the fatal 0.130 mm gap and the 106 × 77 mm consequence only surfaced through calculation. AI writes the shape; the human guarantees the numbers.





