OpenSCAD part designer
Turn a description into a part that prints the first time. The model writes the geometry, and the scripts supply the eyes and the calipers. A part is only done once you have looked at renders of the current version and the checks pass or every warning is explained. Geometry that compiles is not the same as a part that works. Most failures (a hole on the wrong face, a wall that came out 0.8 mm, a lid that overlaps its box) only show up in the renders and the measurements.
Tools
SKILL=~/.claude/skills/openscad-part-designer
PY=~/.venvs/openscad-part/Scripts/python # Windows; ~/.venvs/openscad-part/bin/python elsewhere
| Script | Does |
|---|---|
scripts/render_views.py file.scad [--part p] | 6 PNG views + one labelled contact sheet (preview/<stem>_sheet.png) |
scripts/export_stl.py file.scad [--placement assembled] | one STL per printable part into stl/ (or stl/assembled/) |
scripts/check_part.py stl/x.stl | bed fit, closed solid, bed contact, wall/feature thickness, narrow gaps, overhangs |
scripts/check_fit.py stl/assembled/a.stl stl/assembled/b.stl | interference, touching faces and tight spots between mating parts |
scripts/section_view.py stl/x.stl --axis y --at 20 | 2D cut on a mm grid, several STLs overlaid: walls, internals, gaps |
scripts/slice_check.py stl/x.stl [stl/y.stl] | slices with Cura's engine and the user's own Cura printer profile: print time, grams, and where real support goes |
Run every script with $PY; each takes --help. OpenSCAD is found via $OPENSCAD, PATH, or the default install
folder. If $PY doesn't exist, create it: python -m venv ~/.venvs/openscad-part then
$PY -m pip install -r $SKILL/scripts/requirements.txt.
Project layout (same as the user's existing projects): <project>/<name>.scad, renders in
preview/, STLs in stl/.
Workflow
1. Pin down what the part must do
Before writing geometry, get these straight from the request, attached photos or files, or the user's existing .scad files:
- What it mates with and the dimensions that decide whether it fits: shaft diameter, rail size, board hole pattern, screw size, wall thickness of the thing it clamps.
- Which numbers are measured and which are guesses. A plausible guess that silently became
the real dimension is the most expensive mistake here, because the user prints it and it
doesn't fit. Put every unconfirmed dimension in a
/* [Measure these] */Customizer group, mark itPLACEHOLDER, and list it in the final report. Ask up front only when the whole design depends on it (a D-shaft vs a round shaft changes the part). Otherwise build with a sensible default and flag it. - Load and use: what it carries, what flexes, what slides, and what is screwed or glued.
- Is a fit test worth it? When a fit is tolerance-critical (press fits, snaps, bearings) or a
key dimension is unmeasured, add a small test coupon as an extra
partoption, for examplepart = "fit_test". It's a thin slice of just the critical feature, a few minutes to print, so the user can check it before committing to the long print. The coupon is a printed part too, so it gets checked like one. - Printer: Elegoo Neptune 4 Max (420 × 420 × 480 mm, 0.4 mm nozzle) unless the user says otherwise. Material is PLA or PETG unless stated.
For published standards (screw, nut and insert sizes, Raspberry Pi hole patterns, Picatinny, 2020
extrusion), use the real spec. references/printability.md has a hardware table. Say where
each number came from.
2. Decide the print orientation first
Choose the print orientation before modeling, because it decides which features are easy:
- Faces on the bed need no support. Faces that lean more than 45° from vertical, or flat ceilings with nothing under them, need support or a redesign.
- Layer lines are the weak direction. A hook, clip or bracket arm should be loaded along its layers, not peeled across them. Snap-fit arms should flex in the XY plane. An L-shaped bracket or wall shelf prints on its side, so every layer contains the whole L and the corner that takes the load isn't a layer seam.
- Holes come out round when vertical and sag at the top when horizontal (use a teardrop or a flat top).
- Split a part when no single orientation works, and join it with screws, pins or a dovetail.
Write the chosen orientation and the reason into the header comment.
3. Write the .scad
Start from assets/part_template.scad and follow references/openscad-conventions.md. The
short version, matching the user's existing files:
- A header comment: what the part is, the coordinate frame (where X, Y, Z and 0 are), the print orientation, and the hardware list.
- Every dimension is a named variable at the top, grouped with
/* [Group] */Customizer tabs. Each user-facing variable gets a//comment saying what it is, in mm. Internals go under/* [Hidden] */:$fn,eps, printer and process (bed, nozzle,min_wall), fit clearances, and hardware sizes. No bare numbers inside modules except 0, 1, 2 andepsoverlaps. - A
// ---- Derived ----section, thenassert()s with readable messages for anything that would make the part fail (a wall undermin_wall, bigger than the bed, a hole that breaks through, a clearance that went negative), thenecho()of each part's print size. - One module per part, modeled in the assembled frame. The
partselector (part = "assembly"; // [assembly, a, b]) and theplacementswitch withlaid_out()turn each part onto the bed for printing. Withplacement = "assembled", mating parts export in place forcheck_fit.py. assembly()colours each part and shows the thing it mounts to as a translucent ghost, so the renders show fit and context.- Fits come from named clearances (
fit_press,fit_slide,fit_free), never+ 0.2sprinkled through the code. Cutters extendepspast the faces they cut.
When editing a .scad the user already has, keep its structure, names and style. Don't move it onto the template.
4. Render and look
$PY $SKILL/scripts/render_views.py part.scad # the assembly
$PY $SKILL/scripts/render_views.py part.scad --part bracket # each printable part
Then open the _sheet.png with Read and actually inspect it. Check each of these
against the description:
- Is every requested feature there, on the right face, facing the right way? (Holes go through what they should. The open side of a hook points up. The mounting face is flat.)
- Do the proportions look like the request? Compare the echoed print sizes with the numbers asked for.
- Does each printable part sit flat in its print orientation, with no stray floating pieces?
- Where it mates with the ghost or other parts, does it wrap the right thing?
OpenCSG previews can shimmer where faces cut each other (text and thin cuts look garbled). If
something looks wrong, render that part with --render or render its STL before trusting or
"fixing" it. If OpenSCAD prints an ERROR (failed assert) or WARNING, fix it; warnings are bugs.
5. Export, then measure
$PY $SKILL/scripts/export_stl.py part.scad # stl/<part>.stl, print orientation
$PY $SKILL/scripts/check_part.py stl/bracket.stl # every printable part
$PY $SKILL/scripts/export_stl.py part.scad --placement assembled # only if parts mate
$PY $SKILL/scripts/check_fit.py stl/assembled/box.stl stl/assembled/lid.stl --min-gap 0.25
$PY $SKILL/scripts/section_view.py stl/bracket.stl --axis x --at 12 # where a wall or internal matters
$PY $SKILL/scripts/slice_check.py stl/bracket.stl stl/cap.stl # last, once check_part passes
Pass the real process to check_part.py when it differs from the defaults (--nozzle,
--min-wall, --bed). Reading the results:
- FAIL: fix it. That means not a closed solid, too big for the bed, no flat contact with the bed, walls under 2 perimeters, gaps that will fuse, or parts that overlap.
- WARN: fix it, or say in the report why it's acceptable. Example: "the 22 mm bridge over the cable slot is fine in PETG", or "the 1.0 mm wall is a cosmetic skirt".
- INFO: small arches, hole tops, bridgeable spans, shallow relief, and touching faces that are meant to touch. Mention them only if relevant.
- The coordinates in the report are the STL's own, in print orientation. Use
section_view.pyat the reported spot to see the problem before changing anything. slice_check.pyis the slicer's verdict, using the profile the user prints with (Neptune 4 Max in Cura: 0.15 mm layers, tree support, brim).check_part.pyestimates overhangs from the mesh; this shows where Cura actually puts support, as islands in the STL's coordinates. When the two disagree, trust the slicer. Its time and grams go in the report. If Cura isn't installed it exits with a message; say the slice check was skipped.- Support is a cost (filament, time, a scarred surface), not a defect. Over 10% of the filament is a WARN that asks you to look for a cheaper way to print the same part: another orientation, a 45° face or teardrop on what sits on the support, or splitting the part. Don't buy the support back with function. A side rail that stops sliding, a lip, a clip or a gusset stays as designed; if no orientation avoids the support, keep it and say in the report how many grams and minutes it costs and where it goes.
- Fix a flagged feature; don't delete it to silence the check. If a gusset, rib or clip is thin or overhangs, reshape it (a thicker tip, a 45° face toward the bed) or reorient the part. Removing structure trades a print warning for a weaker part. If you do remove something, say what strength or function was lost and how to get it back.
After any geometry change, re-render, re-export and re-check. The previous images and numbers describe a part that no longer exists.
6. Report
End with this, kept short:
## <Part name>
Files: <name>.scad, stl/<part>.stl ..., preview/<stem>_sheet.png
Print: <part>: <x × y × z> mm, <orientation>, supports <none / where>, ~<time>, ~<grams> g (Cura). Repeat per part.
Checks: <PASS/WARN per part, one line each; fit result if parts mate>
Fits used: <e.g. 0.3 mm slide on the lid groove, 0.1 mm press on the shaft>
Measure before printing: <every PLACEHOLDER variable and what to measure>, or "none"
Hardware: <list, or none>
Tune in the Customizer: <the 3-5 variables the user is most likely to change>
Show the contact sheet path so the user can open it. Don't paste the whole check output; give the result line per part and any WARN with its explanation.
Notes on OpenSCAD versions
- The scripts use the newest unzipped snapshot in
%LOCALAPPDATA%\Programs\OpenSCAD-nightly\(Manifold backend: complex parts export in seconds), else the 2021.01 install. The first line of every script's output names the version. On 2021.01, exports are CGAL and can take minutes: draft with-D '$fn=24', export finals at full$fn. - Write files that also open in 2021.01, which is the version in Program Files: no
roof(),textmetrics(),object()or function literals passed to modules. - Decimal arithmetic isn't exact:
2.4 - 0.6 - 0.6 >= 1.2is false. Give asserts real margin or compare againstmin_wall - 0.001. -Dstring values need quotes. The scripts add them (-D part=lidbecomespart="lid").- Small holes print undersized and polygonal. Use
$fnof at least 32 on holes, or$fn = 6/8on purpose for nut traps. Add fit clearance to diameters, not just radii.