Key takeaways

  • Script-based CAD like CadQuery pairs well with AI assistants because the model is reviewable, parametric text.
  • Build enclosures with the shelling operation and face selectors so walls and cutouts stay parametric.
  • Walls thinner than one nozzle perimeter are not printable; with a 0.4 mm nozzle one perimeter is roughly 0.45 mm.
  • Start tolerances around 0.3 mm for moving parts and iterate; Prusa reports accuracy of at least 0.2 mm on their printers.
  • Check overhang angles, chamfers versus fillets and circle facet counts before sending the model to the slicer.

Small enclosures are one of the best places to bring an AI assistant into hardware work. A box with cutouts, standoffs and a lid is mostly dimensions and relationships, which a language model can draft as code. Instead of clicking through a GUI, you describe the board, the ports and the fasteners, and let the assistant write a parametric script you can review line by line.

This workflow works best with script-based CAD, and CadQuery is a good fit for it. The whole model is text, so the assistant can edit dimensions, add features and fix mistakes without you redoing geometry by hand. The script is only half the job, though: the enclosure still has to print. Print rules from Prusa's modeling guide and the PrusaSlicer layers and perimeters documentation set hard limits on wall thickness, tolerances and overhangs that you should bake into the prompt, not discover after a failed print.

Why script-based CAD suits AI assistants

The CadQuery examples page shows the pattern: you start with a simple box, then add holes, cutouts and shells, all as chained method calls. A model of a plate with a center hole is four dimensions as variables plus a few lines that build a box and cut a hole through it. An assistant can reliably produce and modify that kind of structure.

The key feature is workplanes on faces. As the documentation explains, faces(">Z").workplane() selects the top face of a solid and puts a working plane on it, which "frees you from tracking the position of various features in variables, and allows the model to adjust itself." For an enclosure this means a USB cutout can be positioned relative to the wall it sits on, so changing the enclosure height does not break the cutout.

When prompting, ask for dimensions as named variables at the top of the script, the way the examples do with length, height and thickness. That makes the next round of edits cheap: you or the assistant change one number instead of rewriting geometry.

Prompting the enclosure shell

The core of most small enclosures is CadQuery's shell operation. The examples show cq.Workplane("front").box(2, 2, 2).shell(-0.1) hollowing out a box with uniform 0.1 walls, and the face-selector version .faces("+Z").shell(0.1) removing the top face, which is exactly an open-top case body. More complex selectors like "+Z or -X or +X" can remove several faces at once.

A useful prompt structure: state the outer dimensions, the wall thickness, which face opens, and where internal features go. Then ask for standoffs and cutouts using face selection rather than absolute coordinates. Point lists with pushPoints handle repeated features like four standoff bosses or a vent grid in one call, as the examples demonstrate with multiple circles created from a stack of points.

Run two checks on any generated script. First, confirm the shell thickness matches your printer's wall math (more on that below). Second, confirm holes are sized for real hardware: the polygon example in the docs notes hexagonal holes are useful for 3D printers "whose firmware does not correct for small hole sizes."

Wall thickness is a slicer problem, not just a CAD problem

The hard limit comes from the nozzle. Prusa's modeling guide states that walls thinner than one nozzle perimeter are not printable, and with the common 0.4 mm nozzle the extrusion width in PrusaSlicer is 0.45 mm. Their table gives approximations: one perimeter about 0.45 mm, two about 0.9 mm, three about 1.35 mm.

The subtle part is that you cannot just multiply perimeters by width. As the layers and perimeters doc explains, PrusaSlicer overlaps perimeters slightly to bond them, so the recommended wall thickness for two perimeters at 0.2 mm layer height is 0.86 mm, not 0.90. The doc also notes that changing layer height changes the ideal wall thickness, because layer height feeds into the calculation.

Practical steps for the enclosure:

  • Pick your layer height first, then read PrusaSlicer's recommended thin wall thickness for your perimeter count.
  • Set the CadQuery shell() thickness to that exact value to eliminate perimeter overlap and get a clean wall surface.
  • If you need odd thin walls, enable "Detect thin walls" in PrusaSlicer, but remember walls under one perimeter are still ignored, per the docs.

Tolerances for lids, slots and snap fits

Parts that fit together need clearance, and there is no single correct value. Prusa's guide lists the factors: model size, orientation, the geometry of the interlocking parts, calibration, settings and material properties. An Original Prusa is "accurate to at least 0.2 mm," and materials can warp or shrink on top of that.

For a first iteration, the guide suggests at least 0.3 mm clearance for movable parts. For a friction-fit lid or snap, expect to tweak this over a few test prints. This is where parametric CAD pays off: keep the clearance as a named variable in the script so each iteration is a one-line change.

Also plan for the elephant foot effect on the bottom rim of the enclosure, which changes tolerances near the bed. Prusa's guide points to PrusaSlicer's "Elephant foot compensation" as a fix for affected areas.

Overhangs, chamfers and splitting parts

Enclosure interiors and lids often create overhangs. A printer cannot print in mid-air, and Prusa's guide gives the numbers: clean overhangs land between 45 and 60 degrees depending on nozzle and settings, and their printers with Nextruder and 360 degree cooling (MK4S, CORE One models) reach up to 75 degrees without supports.

For edges, prefer chamfers over fillets when the edge faces the bed. The guide notes that fillets oriented toward the print bed create a very steep overhang that hurts surface finish, so chamfer instead when finish matters. Chamfers on edges of parts that slot together also make assembly easier.

If a geometry is unavoidable, split the model. The guide recommends cutting parts into pieces for better print orientation, gluing them, and modeling in alignment pegs for strength. In CadQuery this is natural: ask the assistant for two separate results sharing the same parameter variables.

Circles, cylinders and hidden facets

Watch what the assistant generates for holes and rounded corners. Prusa's guide warns that modeling software can visually smooth a curve with shaders while the actual geometry is a polygon, so the printed "circle" for your button or port cutout can come out faceted. Check the actual side count in the script or exported mesh.

This matters most for parts that must mate with real components: a USB-C cutout that is a 16-sided polygon may bind where a round hole clears. When you prompt, state the tolerance-critical holes explicitly and ask for them as hole() or circle() calls rather than loose approximations, then verify the export in the slicer preview.

Checking the generated model before slicing

Run a short checklist on every AI-generated enclosure script before it goes to the printer.

  • Confirm the exported model is manifold. Prusa's guide is blunt: a model with surface holes or internal geometry "will not be able to be sliced." Most CAD tools have a repair option, and script-based CAD from solid operations tends to stay manifold.
  • Confirm wall thickness against the slicer's recommendation for your layer height, per the flow math.
  • Confirm hole sizes and clearances with the 0.3 mm starting point for moving parts in mind.
  • Confirm strength orientation. The guide notes FFF prints are stronger in one direction, like wood, so structural parts should be oriented accordingly.
  • Confirm overhang angles in the slicer preview and split or add chamfers where needed.

Some fixes are easier in the slicer than in CAD. The guide notes PrusaSlicer can handle small modifications, modifier meshes for patterns, and adding or removing geometry, which saves a re-export when you do not have the original project handy.

Iterate with versions, not rewrites

Prusa's guide is direct about the process: you will make test prints before the design is final, and "having a parametric approach in CAD helps immensely." It also advises saving versions before merging objects or cutting cavities that must fit something else, because those subtractive steps are hard to undo.

This is where the AI plus CadQuery loop earns its keep. Each test print teaches you one number: a clearance, a shell thickness, a hole diameter. You feed that back to the assistant as a parameter change, regenerate, and reprint. Keep the script in version control the same way you would keep firmware, and keep a note of which print revision each parameter set produced.

Questions readers ask

Do I need to know CadQuery to use AI for enclosure design?

Not deeply, but you need enough to read the generated script. The CadQuery examples are organized from simple to complex and list the API elements used, so working through them is the fastest way to get there.

Why is script-based CAD better for AI than clicking in a GUI?

Because the whole model is text an assistant can write, edit and parameterize, and workplanes on faces let the model adjust itself without you tracking feature positions in variables.

What tolerance should I use for parts that fit together?

There is no universal value; it depends on size, orientation, geometry, calibration, settings and material. An initial good measurement for movable parts is at least 0.3 mm.

Can a slicer fix walls that are too thin?

Only partly. PrusaSlicer's "Detect thin walls" merges two paths into a single-pass extrusion, but walls thinner than one perimeter cannot be repaired that way, so fix them in CAD.

Sources

The AI Hardware Prototyping Stack is a free checklist of tools and prompts.

Circuit Owl Lab wrote this with AI from the sources listed above, and a separate review pass checked its claims against them. Nothing here comes from first-hand testing.