Design 3D-Printable Parts With AI: A Beginner's Guide to CadQuery and build123d
4 November 2026 · 6 min read
If you own a 3D printer, you know the ceiling you keep hitting. You can print anyone else's model, but the moment you need a bracket that fits your shelf, an enclosure for your circuit board, or a spacer exactly 7.3 mm tall, you're stuck. Fusion 360, Onshape and FreeCAD can do it, but they greet a newcomer with a wall of ribbons and constraints.
There's another way: describe the part in words, let an AI write parametric code, run it, check it, fix it, and print it. You don't need to be a programmer. You need to read a recipe, measure with calipers, and tell the AI when it got something wrong.
Code-CAD in one paragraph
There are two ways to represent a 3D shape. A mesh (the STL files you already print) is a skin of thousands of tiny triangles: great for printing, terrible for editing. A parametric solid stores the recipe ("a 20 mm cube with a 5 mm hole"), so changing the hole to 6 mm is a one-number edit. CadQuery and build123d are Python libraries that build parametric solids on OpenCascade, the same CAD kernel under FreeCAD. Because they are just Python, any capable LLM can write them. No special "text-to-CAD" model is needed.
import cadquery as cq
result = cq.Workplane("XY").box(20, 20, 20).faces(">Z").workplane().hole(5)
Change hole(5) to hole(6) and you have a new part. That one-line edit is the whole point.
What AI is good at, and what it isn't
The research is unusually candid. The 2025 paper Text-to-CadQuery found that ChatGPT, Claude and Gemini can all translate descriptions into CadQuery, with GPT-4o producing executable code on the first attempt over 90% of the time.
But "it runs" is not "it's right." The 2026 Text2CAD-Bench benchmark found models do reasonably on basic geometry but degrade sharply on complex topology. As parts got harder, the share of invalid outputs rose from about 15% to between 70% and 90%. Sweeps, lofts and shells are where things fall apart.
The practical takeaway: for everyday maker parts like boxes, brackets, holders, enclosures and spacers, AI plus code-CAD is a superpower. For organic sculptures and freeform surfaces, use mesh tools or expect manual work.
Setup in about 30 minutes
The most popular free stack is VS Code + the OCP CAD Viewer extension + build123d (or CadQuery):
- Install Python 3.11+ and VS Code.
- In VS Code, install the Python extension and OCP CAD Viewer.
- Open the OCP CAD Viewer sidebar and click Quickstart build123d. It installs the library and the viewer bridge for you.
- Run this. If a cube appears in the viewer, you're done:
from build123d import *
from ocp_vscode import show
part = Box(20, 20, 20)
show(part)
export_stl(part, "hello.stl")
For the AI side, you can paste prompts into Claude or ChatGPT and copy code back, or use an in-editor agent like Claude Code, Cursor or GitHub Copilot that can run the script and read its errors itself.
The brief is everything
Treat the AI like a brilliant but literal-minded intern. It builds exactly what you say and guesses badly at what you leave out. Every brief should state units, overall size, origin, features with positions, mounting, fits, printer and orientation. The single highest-leverage line is the last one in this template:
Write build123d (builder mode) Python code for a functional 3D-printable part.
PART: [one-line description]
UNITS: millimeters
OVERALL SIZE: [L x W x H]
ORIGIN: part sits on XY plane, base at Z=0
FEATURES:
- [hole/slot/pocket + position + size]
MOUNTING: [screw size, hole spacing, counterbore?]
FITS/TOLERANCES: [e.g., M3 clearance holes = 3.4 mm; lid gap = 0.2 mm]
PRINTER: 0.4 mm nozzle, PLA, 0.2 mm layer height
ORIENTATION: designed to print flat with no supports
REQUIREMENTS:
- Put ALL dimensions as named variables at the top.
- Use chamfers (not fillets) on the bottom edge.
- End with show(part) and export_stl(part.part, "part.stl").
Parameters at the top turn the AI's output into something you can tweak without prompting again.
The design loop: generate, run, view, measure, fix
Nobody gets the part right on the first prompt. The most powerful move is to paste the exact error back to the AI. Text-to-CadQuery found that feeding execution errors back raised the execution success rate from 53% to 85%.
The usual mistakes:
- Wrong orientation. The part is on its side. Say which face is up and that it prints on the XY plane.
- Invented API calls. Paste the
AttributeErrorand ask for real build123d API only. BRep_API: command not doneon a fillet. This almost always means the radius is too big for the wall. Tell the AI the wall thickness and ask for a smaller radius.- Feature on the wrong face. Name the reference face explicitly.
- Runs, but looks wrong. A screenshot of the viewer plus one sentence ("the hole should be on the top face, not the side") works remarkably well with vision-capable models.
Design for the printer, not just the screen
A geometrically perfect model can still print badly. These are documented starting points for a 0.4 mm nozzle; calibrate them on your own machine:
- Walls should be multiples of the nozzle width: 0.8, 1.2 or 1.6 mm. Keep load-bearing walls at 1.2 mm or more.
- Holes print undersized. An M3 screw needs a clearance hole of about 3.4 mm to pass.
- Lids and snap fits need about 0.2 mm of gap per side.
- Overhangs steeper than 45° from vertical need supports.
- Chamfer the bottom edge, don't fillet it. A rounded bottom creates an instant steep overhang, while a 45° chamfer is self-supporting and hides elephant's foot.
- Orient for strength. FDM parts are typically 4 to 5 times weaker between layers, so a bracket printed flat is far stronger than the same bracket printed upright.
Verify before you waste an hour of print time
Check the size in code before you slice. If you asked for 60 mm and the bounding box says 6 mm, you've found a units bug for free:
from build123d import *
with BuildPart() as part:
Box(60, 40, 20)
bb = part.part.bounding_box()
print("Size (mm):", bb.size.X, bb.size.Y, bb.size.Z) # expect 60 40 20
Then load it in your slicer, confirm the dimensions, look for "non-manifold" warnings, and preview the layers for unsupported overhangs. For any fit that matters, print a small tolerance coupon first. Ten minutes of coupon beats a three-hour failed enclosure.
The magic isn't one perfect prompt. It's a tight loop between you, the AI and a live 3D preview.
This article is adapted from our ebook Prompt to Print, which covers code-CAD basics for non-programmers, heat-set inserts and nut traps, parametric part families, sharing on MakerWorld and Printables, and a full walkthrough of an ESP32 sensor enclosure with a snap-fit lid.