Workflow rules (AGENTS.md)¶
This is the text every agent works from: the MCP server serves it as b123d-print://guide and
inside every prompt, and b123d-print init writes it to a workspace as AGENTS.md. It is
included here verbatim from the package.
This workspace holds parts for FDM 3D printing, modeled in Python with
build123d and checked with b123d-print. These rules apply to
any agent (Claude, Gemini, GPT, local models) and to humans. They come from parts that were
actually printed; several rules exist because a print failed without them.
Tools¶
Use the b123d-print MCP server tools if your client has them (new_part, write_part,
build_part, render_preview, section, check, check_fit, export, list_faces, list_edges, make_template,
trace_outline, recipe, render_sketch). read_guide returns this guide: call it once before the first part
in a session if your client has not loaded it (the b123d-print://guide resource). Otherwise
use the CLI:
b123d-print new <name> [--sketch]— scaffoldparts/<name>/<name>.py(--sketch: sketch first, below)b123d-print sketch <name> [<sketch>]— draw and check a 2D sketch fromsketches(d)uv run parts/<name>/<name>.py [--variant <key>] [--formats 3mf,png] [--only <pieces>]orb123d-print build <name> [--only <pieces>]— export toparts/<name>/out/and run the checksb123d-print check [<name> ...]— checks only; exit code 1 on any failureb123d-print fit [<name>]— fit between the pieces ofassembly(d): overlaps, gaps, hole alignmentb123d-print trace <image> --dpi N | --grid MM | --reference card— a scan or grid photo to an outline in mmb123d-print recipes [<name>]— tested snippets for common features (teardrop, nut trap, snap arm, ...)b123d-print config— show the print settings in effect (hole compensation, clearance, limits)b123d-print to-step <file.stl>— convert a mesh to STEP and report what the conversion didb123d-print faces <name>/b123d-print template <name> --slice XY:3 | --face ID | --crop x,y,z:sx,sy,sz— list flat faces; make a fit-test template (see below)b123d-print diagnose <name>,b123d-print params <name>,b123d-print set <name> FIELD=VALUE,b123d-print measure <name> --distance A,B | --wall x,y,z | --faces ID,ID | --hole ID— as below
After a failed build, read its DIAGNOSIS (cause, where, fixes with numbers) before changing
the script; diagnose_failure looks deeper. Change a dimension with set_params (params
lists them), not a rewrite of the script. Check fits and walls with measure (gap or
interference, wall at a point, two faces, a hole), not by eye from a render.
Pick fillet and chamfer edges with list_edges (CLI b123d-print edges: ids, convex or
concave, the faces each joins), then highlight=<ids> for a picture and a verified selector to
paste into the script; never put edge ids in the script, they change with the model.
The part script¶
- One script per part at
parts/<name>/<name>.py. Units are mm. - Every dimension is a named UPPER_CASE field of a frozen
Dimsdataclass, with a comment saying where it came from (measured, typed by the user, standard, estimate). No magic numbers in the geometry code. Derived values are@propertys. - Variants (a bigger one, a tilted one) live in the same script, never in a copied folder:
VARIANTS = {"": {}, "140": dict(PLATE_W=140.0)}holds only the overrides. Output files get the variant suffix;--variant <key>builds one, the default builds all. build(d)returns the printable part (or{"name": part}for several), in print orientation, bottom face on Z=0. For several pieces, make the values zero-argument functions (lazy pieces):{"end_rear": lambda: end_rear(d), "key": lambda: key(d)}. Each is built only when that piece is needed, soparts=(MCP) or--only(CLI) builds just the pieces named. Plain shapes work too, but then every call builds them all.- If the part mates with something,
assembly(d)returns the parts in assembled position plus simple stand-ins for the things they mate with (board, sensor, screw). Place mating pieces by face contact and hole axes withplace_on(piece, face_a, target, face_b, offset=0)andalign_axis(piece, axis_a, target, axis_b, clock=...)instead of hand-computedPos/Rotmath. The overlap check usesassembly(d): nothing printed may intersect a stand-in. views(d)lists cross-sections saved with each export;checks(d)declares wall checks and changes the automatic checks (see below);templates(d)lists fit-test templates exported with every variant (Template.slice("XY", 3),Template.face_of("bottom"),Template.crop(...)).
Sketch first (optional, offer it per part)¶
For a part that is mostly a 2D shape made solid, offer to draw and confirm the 2D sketch
before any 3D: outlines extruded flat (brackets, plates, clips, spacers, gaskets), profiles
revolved (knobs, pulleys, spool parts, bushings) and sections swept (hooks, handles). Not for
boxy enclosures (box, shell, lid) or organic shapes (use organic). The user may say no; then
model as usual.
- Confirm the dimensions as always.
new_part(name, sketch_first=True)(CLInew --sketch) scaffolds a script whose optionalsketches(d)hook returns named 2D shapes, lazy like pieces:{"outline": lambda: outline(d)}. - Draw the outline from points, not from unions of boxes and circles:
rounded_outline(points, radii)(one radius per corner, 0 = sharp; it refuses radii that do not fit) andslot(a, b, width)fromb123d_print.recipes, holes cut withCircle((d + HOLE_COMP) / 2). A profile to revolve is drawn onPlane.XZ. A traced outline (trace_outline) can be the points. render_sketch(name, sketch=...)(CLIb123d-print sketch): a PNG on a mm grid with its dimensions (overall size, holes, slots, inside corner radii, centres from the lower-left corner) and the sketch checks: one closed region, narrowest neck vsmin_wall, inside corners under R0.5 (BP-R1), holes under 1 mm, the bed. Fix every FAIL, show the picture, and wait for the user's OK on the sketch.build(d)extrudes, revolves or sweeps the same function's result, then adds the 3D-only features (countersinks,bed_chamfer, which also chamfers inside radii); then the usual flow.
Declared bought hardware (optional)¶
Use from b123d_print import Hardware and an optional variant-aware hardware(d) hook for
user-confirmed bought parts. For example, with confirmed count/specification fields in Dims:
def hardware(d):
return [Hardware("fastener", "Assembly fastener", d.FASTENER_COUNT,
specification=d.FASTENER_SPEC)]
Hardware(id, description, quantity, specification="", location="", note="", source_url="",
source="", units="", needs_confirmation=False, model=None) requires a stable unique ID and a
positive integer quantity for the whole selected variant's assembly, even with parts= /
--only. Leave an unknown specification empty, or mark a partial one needs_confirmation=True;
ask the user instead of inferring a thread, screw length/head, insert model or shopping list
from holes or meshes. Keep assembly instructions in PRINT_NOTES.
Hardware.from_bd_warehouse("fastener", screw_or_nut_or_washer, quantity=d.FASTENER_COUNT)
reuses bd_warehouse's declared class/type/size/length and handedness; add confirmed material,
finish or supplier information as needed. Custom hardware can supply model=<shape or lazy
zero-argument factory>, with explicit source and source-model units. A factory may call
import_model("ref/hardware.stl", scale=<confirmed units>) (STEP/3MF work too): units metadata
does not scale geometry, so match it to scale. Keep assets in ref/ for handoff. Put the
placed shape in assembly(d) using item.standin(placed_shape, label="instance") (or
item.standin() to evaluate its model); use place_on / align_axis for placement. Keep these
nonprintable stand-ins out of build(d); they retain the item ID and existing fit checks.
formats="print,hardware" writes the print sheet's Declared hardware table and optional
versioned <name>[_<variant>]_hardware.json; both use the same ID-sorted whole-assembly counts,
separate from inferred screw-hole advice. all includes both, defaults stay unchanged. Include
print,hardware when filtering a download or pull; source and ref/ come home too. Descriptions
and source URLs are data, never fetched or executed. A missing hook preserves the legacy sheet.
When the part has hardware, offer hardware_list (CLI b123d-print bom): the shopping list
in the result as one table to show the user, identical items merged, count= for several
assemblies, several parts merged; format="csv" for a spreadsheet. The bom / bom_csv export
formats write it as _bom.md / _bom.csv. Settle every check before ordering item with the
user; never fill in a specification yourself.
Repeated features: patterns, one boolean¶
Holes, bosses, ribs, slots and cells that repeat are placed with build123d's location sets, not
computed in a for loop with a boolean on every pass
(guide):
GridLocations(x_spacing, y_spacing, x_count, y_count)(centered),PolarLocations(radius, count, start_angle=0, angular_range=360, rotate=True),HexLocations(apothem, x_count, y_count)(neighbours 2 x apothem apart),Locations(*d.POINTS), andmirror(shape, about=Plane.YZ)for the other side of a symmetric part.- One boolean for all the copies:
part -= GridLocations(...) * hole(a list of placed copies),part += [rib(p) for p in d.RIBS], or awith GridLocations(...):context inBuildPart/BuildSketchwithmode=Mode.SUBTRACT. A boolean per pass costs far more: 400 holes took 0.22 s fused and 10.2 s one at a time.build_parthints at such loops. - Recipes:
bolt_circle,hole_grid,hex_grille(honeycomb vents, lightening),slot_grille(vents, speaker slots),grip_ridges,ribs. Continuous features (threads, flutes, spirals) are one sweep or loft, not thousands of copies. - Webs between copies at least 2-3 lines [W2, W3], holes at least 1-2 mm [H5], rows of horizontal holes as teardrops [H3], hex cells in a standing wall corner-up [O1].
Big and multi-piece projects¶
A part that takes long to build makes every step slow. The time limit is 240 s per call.
- Read the timing report.
build_part(andb123d-print build) lists each piece's face count and build time, with a hint on a piece over ~1,500 faces or ~10 s. Fix that piece first. - Build each distinct piece once, then mirror or copy it.
front = mirror(rear(d))builds the rear piece a second time. Put@functools.cacheon the piece function (Dimsis frozen, sodcan be its key), or build once and place copies. - Keep curves to the points they need. Build time grows with the point count: a 96-point polyline offset and extruded several times makes thousands of faces. Halve the points if the part still looks and fits the same, or use a spline where offsets of it stay robust.
- Work on one piece at a time with
parts="end_rear"onbuild_part,render_preview,sectionandexport(--only end_rearon the CLI). Never invent a variant just to build fewer pieces. - Built pieces are cached in
out/.cache/per variant.render_preview,section,checkandexportreuse them while the script, its folder's.pyfiles, the files it reads in its folder, the Dims and the settings stay the same.fresh=Truerebuilds. A build that reads a file elsewhere in the workspace, or a remix that loads a model, is not cached.checkalso reuses each unchanged piece's findings, andexportskips files and templates already up to date. - Consider one part script per piece when pieces share little but their dimensions, so each builds, checks and exports on its own.
Print rules¶
The IDs in brackets ([H3]) point to the sourced rules in BEST_PRACTICES, where each one has its sources and range of values. Provisional marks a rule with only one source so far: follow it as a starting point, say so in the report, and never turn it into a default or a check.
Fits and clearances (all per side; say per side or total in every report) [F4]
- Fit values come from the user's settings, measured with the
fit_couponexample; read them withs = load_settings(__file__):s.press_fit(pressed together, ~0.05),s.clearance(sliding, the default fit, 0.2),s.free_fit(turns or moves freely, 0.3),s.pip_clearance(parts printed in place, 0.3). Use a named field (CLEARANCE,FREE_FIT, ...) and the user's own value if they give one. [F1, F2, F3, N6, J3, W7] - Don't design a fit that needs better than ±0.2 mm without a coupon; over ~100 mm in ABS, ASA or nylon, mating features far apart drift with shrinkage: place them relative to each other. [F5]
Holes
- Holes are modeled true to size; the slicer corrects them (its X-Y hole compensation, set
from the
hole_couponexample). Keep hole fields at the target printed size; a fit adds the clearance (a hole for a 4 mm dowel, sliding: 4 + 2 × clearance). Still cut every hole withHOLE_COMP: float = hole_comp(__file__)added (HOLE_COMP_H: float = hole_comp(__file__, horizontal=True)for holes lying on their side): both are 0 unless the user opted in to build the correction into the files (then they are for that printer only, with the slicer's at 0). Never hard-code a value from somewhere else. Report holes with their cut size. [H1, H2, H4] - Horizontal holes get a teardrop (45° pointed roof) or a flat bridged roof, or turn the part
so the hole is vertical; the
holescheck warns on round ones. [H3] - Holes that must be precise (bearings, shafts): model them slightly small and ream to size; say so in the report. [H6]
Overhangs, bridges and supports
- Keep downward faces within the overhang limit (45° from vertical unless the user's
max_overhangsays more). [O1] - A flat ceiling must rest on walls on two opposite sides (a bridge, no longer than
max_bridge, 10 mm by default) or get supports; a ceiling hanging off one wall is an overhang. The overhang check reports both. [O3, O4] - To avoid supports, in this order: turn the part, chamfer the overhang, split the part, use teardrop or pointed roofs; then supports. Say in the report what needs supports; supported surfaces come out rough. Gaps that support must be cleared out of: at least 5 mm. [S1, S2]
- For test coupons or deliberate overhangs, declare PRINT intent with a why:
PRINT = {"supports": "none", "why": "..."}(alsowalls,infill,infill_pattern,brim,orientation: "locked"). The print sheet keeps the facts and labels the advice "set by the part";checkreports the overhangs as accepted, and a FAIL stays a FAIL. - Provisional (one source, Hackaday): a hole in a ceiling (a counterbore or nut trap opening downward) can print over a one-layer "sacrificial bridge" that is drilled out afterwards. [O5]
Strength and orientation
- Layers are the weak direction: across them a part has roughly half its strength (much less in ABS/ASA). Orient or split parts so the main tension or bending runs in XY (along the layers): snap arms lying flat, hooks and brackets not standing on their tips. State the load direction and the orientation in the report. [S4, S5, N1]
- Before exporting, run
suggest_orientation(CLIb123d-print orient) if the part isn't obviously flat-bottomed; passload=for a part that carries load, and apply theRot(...)it gives inbuild(d). A tall part on a small footprint warns incheck(tip-over): lay it down, or tell the user to use a brim or mouse ears. [B6] - Strength comes from walls (perimeters), not infill: size walls and ribs for the load, keep at least ~1.2 mm (three lines) where strength matters, and make walls whole multiples of the line width. Say in the report which features need more slicer perimeters (screw bosses: 3-4 or more). [W3, W4, T8]
- Fillet internal corners of loaded features (snap-arm roots, pin bases, brackets), at least 0.5 mm and more where there is room. Outside corners print rounded at nozzle scale anyway; never design knife edges. [R1, R3]
- Ribs and gussets as thick as the wall (no reason to thin them in FDM; at least ~1.5 mm); use them to stiffen large flat walls and against warping. [R4, R5]
- Provisional (one source, Stratasys Direct): on a bent wall, outer radius = inner radius + wall thickness keeps the wall even. [R2]
Bed, first layer and warping
- Edges on the bed get a chamfer, not a fillet (a fillet there is an overhang and flares),
unless the user says otherwise; the
bed edgecheck warns. Break other sharp edges (~0.5–1 mm). Keep the CAD at nominal size: elephant's foot is the slicer's job. [O2, B1] - Provisional (one source, a Bambu forum post): ~0.4–0.6 mm is a typical bed-edge chamfer. [B2]
- ABS, ASA, PC and nylon warp: for parts over ~100 mm in them, round the footprint corners, break up large flat solid areas, add ribs, and tell the user to use an enclosure and a brim. PLA, PETG and TPU rarely warp. [B3, B4]
- Shrinkage is compensated per filament in the slicer; keep the CAD nominal. [M1]
Shapes from profiles: hollow, loft, sweep, revolve (recipes)
- Hollow a body with
hollow(part, wall, open="top")(build123doffset(-wall, openings=)), never by subtracting a smaller copy: the wall stays even round fillets and curves. Hollow the plain body first, then add bosses, ribs and holes; outside corner radius ≥ 2 × wall keeps the inside corners round. Enclosures: therounded_enclosureexample. [W3, W4] - A part whose section changes along its length (duct and hose adapters, round to square,
funnels):
transition_loft(a, b, length, wall=, collar_a=, collar_b=); the sides within the overhang limit inside and out, about 1 mm of change in radius per 1 mm of length (thehose_adapterexample). [O1] - A constant section along a path (hooks, handles, rails, cable channels):
swept_section(path, section)with aFilletPolyline, arc orSplinepath drawn in XY, so the part lies flat and its load runs along the layers. A changing section:tapered_sweep. [S4, S5] - A round part (knob, pulley, wheel, spool end, bushing): draw the half outline as (r, z)
points and
revolved_profile(points, radius=...); corner radii in the profile, bed corners sharp and chamfered. [O1, B1]
Snap fits and living hinges
- Use a recipe (
recipetool,b123d_print.recipes) before improvising a snap arm, hinge, nut trap, teardrop hole, lid lip, text, bed chamfer, hollow, loft, sweep or revolve: they are tested and cite their numbers. - Snap arms: lie flat (bend in XY), root fillet ≥ 0.5 × arm thickness, taper the arm toward the tip. [N1, N2, N3]
- Provisional (one source, Fictiv): size the arm with the cantilever strain formula and an allowable strain of PLA 4–8 %, ABS 7 %, nylon 4–15 % (halve it for arms along Z); say it is an estimate. [N4]
- Provisional (one source, Sovol): arm length/thickness ~8–10 for PLA, ~5–8 for PETG. [N5]
- Living hinges: 0.4–0.6 mm thick (at least two layers), in nylon, TPU or PP, not PLA or ABS;
build the hinge width along Z so strands run across the hinge. A hinge is thinner than
min_wall: list it inThinFeature(..., ignore=[box]). [N7, N8, N9] - Provisional (one source, Hubs): working a nylon hinge in boiling water and letting it cool closed makes it last longer. [N10]
Threads, screws and inserts
- Model threads only at M5–M6 and up; smaller: heat-set inserts, captive nuts or screws into a pilot hole. Use inserts or nuts for parts opened more than a few times. [T1, T5]
- Heat-set inserts: the insert maker's hole size (CNC Kitchen M3: 4.0 mm) plus
HOLE_COMP, blind hole depth = insert length + 1 mm, wall around it at least the maker's minimum (M3: 1.6 mm; add aWallcheck); install at print temperature + 10–20 °C. [T2, T3, T4] - Self-tapping or thread-forming screws: pilot holes vary by material and orientation (M3 ≈ 2.6–2.9 mm); print a test pair for anything that matters. [T6]
- Captive hex nut pockets: across-flats + 0.2 mm total. [T7]
Threads, fasteners and gears: the libraries (guide)
- Use the libraries instead of drawing standard parts:
bd_warehouse.thread(IsoThread,PlasticBottleThreadfor jars and bottles),bd_warehouse.fastener(screw, nut andHeatSetNutsizes),bd_warehouse.open_builds(2020 V-slot rail and T-nut as stand-ins),py_gearworks(spur, helical, herringbone, bevel gears and racks;mesh_toplaces a pair). - Modeled threads: M6 and up, coarse pitch or bottle threads, axis on Z. Pass the user's
clearance as
manufacturing_compensation(radial, per side), and fade or chamfer the ends. Below M6, use an insert, a nut or a pilot hole. [T1] - Holes from bd_warehouse are compensated once.
ClearanceHoleandTapHoletake no compensation, so read their sizes (screw.clearance_hole_diameters["Normal"]) and cut them with+ HOLE_COMP.InsertHolecuts the table's drill size, not the maker's hole (CNC Kitchen M4: 5.79 vs 5.6), so cut the maker's size yourself. [H1, T2] - Gears: module ≥ 1 (1.5–2 better), backlash on each gear (0.1–0.2 mm per gear), profile shift
(17 - z) / 17below 17 teeth, printed flat, bores chamfered on top only. Put the meshed pair inassembly(d)with aGapcheck between them. - V-slot: a V key with 45° sides in the slot's groove, shallow enough to clear the T-nut's neck,
with the rail and T-nuts as stand-ins in
assembly(d).
Text, splitting and gluing
- Text: on top (XY) faces, ≥ 0.5 mm deep or high (a multiple of the layer height), strokes ≥ ~1 mm, characters ≥ ~5 mm, bold sans-serif. [X1, X3]
- Text on a curved face (jar, knob, dome): the
text_on_surfacerecipe,method="wrap"on one face (keeps the size),"project"across face edges (stretches on slopes); along an arc:text_on_path. Same minimums, measured on the surface; sunk text forgives thin strokes more than raised. The text is its own solid: a second colour ispart & text(sunk) ortext - part(raised). A face that does not mesh failscheck(a hole in the STL). - Text or a logo in a second colour (AMS / MMU): the
inlayrecipe, orbodies(base=..., inlay=(shape, "white"))with each pocket cut by its own insert. The 3MF is one object with a named, coloured part per body; checks run on the union plus abodiesoverlap check. Inlay ≥ 2 layers deep. - Split a part when it exceeds the build volume, would need a lot of support, or when pieces can each print in their strongest orientation. Join with a dovetail and dowels or alignment pins (clearance from the fit settings); a glued joint still needs a mechanical key. Glue: CA bonds every common filament; acetone welds ABS/ASA; PETG takes only CA or epoxy. [J1, J2, J4, J5]
Splitting a part¶
When a part does not fit the bed in any orientation (the fit check fails, or it is bigger than
the user's bed), or would print much better in pieces: [J1]
(guide)
- Propose the cuts and the joint, with reasons, and wait for confirmation: where the load is low, along a design line where the seam hides, so each piece lies on a big flat face without supports and with its load along the layers [J6]. Name the joint: a bowtie key plus square pins for long seams, a dovetail to slide together, inserts and screws to take apart, a lap for glue area [J2].
- Use
b123d_print.joints, never hand-made joints:split(part, plane, [Bowtie(...), Dowel(...), ...], clearance=d.CLEARANCE)returns the pieces (.a,.b), the loose keys and pins laid flat (.loose) and placed (.placed, forassembly(d)). Joint sizes are namedDimsfields. AddGapchecks on a key or pin andWallchecks around the joint features. - Offer a fit-test template of the joint first (
Template.croparound the cut, each side), printed with a loose key or pin, before the full pieces. - Assembly notes in the report: the order, the adhesive for the gap (thin CA on faces that touch; CA gel with activator or epoxy in a clearance fit) and clamping [J7]; how to fill and sand the seam if it shows [J8].
Remixing an existing model¶
When the user gives you someone else's model (STL, 3MF or STEP) to change:
- Get it onto the server into
parts/<part>/ref/:upload_referencesays how for this connection (a folder to copy into,b123d-print push, or a signedcurl -fTlink). - Inspect before anything else:
describe_model(size, units, faces, curved share, holes, repairs, metadata) and its render. A size that suggests inches or cm: ask, thenimport_model(..., scale="inch"). - License: record the source URL, author and license in the script's docstring. -ND allows no remixes: stop and tell the user. -NC: no commercial use. BY: the author must be credited when it is shared. If the file does not say, ask.
- Propose MODIFY or REDRAW, with reasons, list the intended changes as named dimensions, and wait for confirmation. MODIFY is the default: always for STEP, and for organic or detailed meshes. Offer REDRAW for a simple prismatic mesh whose proportions change.
- MODIFY:
base = import_model("ref/<file>")inbuild(d), then cut and add features with namedDims. Keep the original where the file puts it; if you turn or move it, defineoriginal(d)returning it placed the same way. Mesh curves stay faceted: to change a round hole, cut a real cylinder at its center (fromdescribe_model), withHOLE_COMP. - REDRAW: model it from
Dims, defineoriginal(d)returning the import placed like the redraw, and callbefore_afterbefore changing any proportion; report the score. - Findings "inherited from the original" were already in the original: report them, but do
not "fix" them unless the user asks. Fix every new FAIL. Show
before_afterin the report, and give the attribution line to use when sharing (e.g. "Remix ofby , , ").
Replicating a physical part¶
When the user has a physical part (often injection-molded) and wants a printable copy, use the
replicate_part prompt's phases (guide).
parts/<name>/MEASURE.md is the replication spec and the source of truth for every measured
value: | Feature | Value | Method | Accuracy | Status | Class | Source | Field | Why changed |.
- Identify what it does, what it mates with and how, how it is loaded and how it was made; ask for the mating parts, the material (a recycling mark), heat, sunlight and how often it comes apart.
- Plan the measurements and wait: one row per dimension, values empty, with the method,
accuracy, Class and the Dims field it becomes. One datum, not chained; three readings of each
critical size in the Value cell (
4.21, 4.19, 4.22); on a molded wall, say where it was measured (where it mates, or mid-height) [C2]; threads by diameter and pitch; the photos to take [C10]. Never guess a value. - Classify and decide, and wait. Class
critical(mating interfaces, hole sizes and spacings, fits, sealing and bearing faces, snap and latch geometry, threads, the envelope where it fits) orfree(styling, ribs, coring, walls away from interfaces). Sourcemeasured,standard,derived,changedorestimate. Critical sizes are modeled as measured, or with the reason in Why changed. A molded part is already at nominal size: never add or remove molding shrinkage [C12]. - Molded features, each change with its reason in Why changed:
- Draft: remove it; keep a taper only where it does a job (a taper fit, nesting) [C1].
- Coring and thin even walls: solid or thicker in a print; keep pockets that do a job [C3]. Ribs: keep where they run, as thick as the wall, or drop them where solid replaces them [C4].
- Sink marks, parting lines, flash, ejector-pin marks, gates, knit lines: never modeled or measured on [C5].
- A living hinge is redesigned (0.4–0.6 mm nylon, TPU or PP, or a pin hinge) [C6]; a snap arm is recomputed for the print material and printed flat [C7].
- Bosses: the position and the screw, not the molded proportions; inserts for screws taken out often; threads only M5–M6 and up; declare the screw as hardware [C8].
- Material: pick by what the molded resin was chosen for (heat, strain, sunlight, sliding); say the copy is weaker across its layers [C9].
- Model every row with a value as the
Dimsfield named in its Field column (or an expression of fields); verify with the usual checks, thenreplication_specuntil it has no warnings,measureon the critical features, and a fit-test template of each critical interface. With a scan of the part,original(d)andbefore_afteras in a remix. - Provisional (one source, Hackaday): round a reading to the value the designer meant (43.97 → 44 mm, inch vs mm, standard sizes) and say so in Why changed [C11].
Output formats¶
export writes, per printable part: STEP (opens in other CAD — Onshape, Fusion, FreeCAD —
as a plain solid without feature history), STL and 3MF (slicers; 3MF keeps units),
and PNG previews plus the section views. The user picks: the formats setting in their
config, or formats="3mf,png" on one export. If the user has not said what they need and the
setting is the default, ask once (e.g. "3MF for Bambu/Orca/Prusa, STEP to edit in other CAD?").
The parametric source is always the .py script and its Dims.
A multi-body part (bodies(...)) exports one 3MF object with a named, coloured part per body
(tell the user to give each part its filament in the slicer), a union STL plus one per body.
export sorts parts/<name>/out/ by purpose: print/ (3MF, STL and the print sheet: what the
user opens in the slicer; fit-test templates in print/templates/), cad/ (STEP, GLB), images/
(previews, sections, before/after, compare) and docs/ (BOM, hardware JSON, the 3D view HTML),
plus a short out/README.md index. Point the user at out/print/ for the slicer. Only the
script, ref/ and b123d-print.toml need keeping: one export makes out/ again.
The print sheet (formats="print", off by default) writes out/print/<name>_print.md for the
slicer: sizes, filament and time estimates, supports, tip-over, walls and infill, fits and hole
compensation. Offer it when the user prints the part themselves; put assembly order, glue and
inserts in a PRINT_NOTES field so the sheet carries them.
After an export, offer the 3D view so the user can turn the part in a browser before printing:
the view link export returns over HTTP (no token, it expires), or locally the
out/docs/<name>_view.html it names (opens offline); view="assembly" shows the assembly.
Remote server: bring the part home (required last step)¶
Locally (stdio) everything is already in the project folder:
parts/<name>/<name>.py the script (the parametric source)
parts/<name>/out/print/... 3MF, STL, print sheet: what goes to the slicer
parts/<name>/out/cad/... STEP, GLB
parts/<name>/out/images/... renders, section views
parts/<name>/out/docs/... BOM, hardware JSON, 3D view HTML
parts/<name>/ref/... reference models (remixes)
Over HTTP or SSH that same layout lives on the server, and the server is a workbench, not storage: its copy is a temporary working copy, deleted after some days unused (the results say how many). Use only the MCP tools and the links they return: the server gives no shell, ssh or scp access, so never try them.
A part is not done until its files are on the user's machine: after export, call
download_part (embed=True if your shell has no network) and unzip into the project folder,
unless the user says to leave them on the server. A remote export or make_template result
ends with this as its NEXT STEP. Before reporting, always:
download_part("<name>"). Over HTTP it returns one link (no token, it expires): runcurl -fLo <name>.zip '<link>'and unzip it in the project folder (unzip -o <name>.zip; Windows:tar -xf <name>.zip); it createsparts/<name>/...as above. Over SSH it returns theb123d-print pull <name> --from ...command: run it in the project folder. If your shell has no network or is sandboxed (Antigravity/agy, web and mobile clients), calldownload_part("<name>", embed=True): the zip (up to 8 MB) comes inside the result, and your client saves it to a file; rununzip -o <saved zip> -d <project folder>(one command, no&&or|).- Check the files exist on the user's machine (e.g. list
parts/<name>/out/print/). - Then report, saying where the files are.
If the client cannot run commands, give the user the link (or the command) and say the part is
not on their machine yet. variant= and formats= narrow the out/ files; per-file links from
export and the b123d-print://files/ resources still work for single files.
Versions and resuming a project¶
The project folder can keep a version history (git on the user's machine, made simple):
save_version, list_versions, restore_version (CLI b123d-print save, versions,
restore). A save takes each part's script, ref/, MEASURE.md and the .py files beside the
script, plus b123d-print.toml; never out/.
- Offer, never decide: after a change that built and passed its checks, ask "Save this
version? (shelf_bracket: arm 115 → 130 mm)" and call
save_versiononly on a yes. Before a restore, ask too. Nothing is saved automatically. - No history yet (the tools say so): offer once to start one; on a yes,
save_version(..., start=True)(CLIb123d-print init --git). It writes a.gitignorethat keeps outout/, downloaded zips, tokens and client configs. restore_version(part, <number from list_versions>)saves the old files as a new version: nothing is lost, and it is refused while the part has unsaved changes (offer to save first). Thenbuild_partandcheck.- Shared server (HTTP/SSH): the history stays on the user's machine, never on the server; the tools return the commands for the user's project folder. Bring the part home first.
- Resume a project: when a part the user has at home is missing on the server (unused
workspaces are removed after some days), put it back from their copy:
new_part(name),write_part(name, <their parts/<name>/<name>.py, whole>), thenupload_referencefor each file in itsref/(over SSH theb123d-print pushcommand it gives); settings they had inb123d-print.tomlgo back withsave_setup. Never re-create a script from memory.
Printer profile (optional)¶
By default b123d-print is in generic mode. When list_parts shows no printer (generic mode), offer
the first-run setup once before the first part (the setup_workspace prompt; CLI b123d-print
setup): printer, material, formats, style, then the calibration coupons. If the user has set a printer (list_parts shows it, or
b123d-print printer show), use it: keep the part inside the build volume in print orientation
(the fit check fails otherwise — split the part or turn it), make walls whole multiples of the
line width, and read the material notes (e.g. PLA is not for outdoor or hot places). Change the
printer only when the user asks.
Photos and measurements¶
- Before modeling: list every dimension you read from the photos and which feature it belongs to, list features you can see that have no dimension, and wait for the user to confirm. Do not start modeling on guesses.
- Photos show intent; typed measurements are truth. If a photo reading conflicts with a typed number, flag the conflict and use the typed number unless told otherwise.
- Missing or ambiguous dimension → ask. Don't guess. If you must assume something to make progress, name it as an estimate in its comment and in your report.
Getting measurements (the user's guide: Measuring for the AI)
- Ask for what decides the model: the units (confirm every converted inch value in mm), the datum every value is measured from, the critical dimensions (what must fit what, and how: press, sliding, free) and the accuracy of each value. Measuring from one datum beats chaining; ~0.1 mm is plenty for FDM.
- Suggest the method for the part: calipers for small precise parts; a flatbed scan (known DPI) or a square-on photo on a grid mat for flat outlines; a profile gauge, radius gauge, bent wire or tracing for curves; a table of offsets (stations at a fixed spacing along a datum line, one height or width per station, level or along the surface stated) for large or curved parts, plus a test section.
- Trace a scan instead of measuring a flat outline point by point:
upload_referencethe image,trace_outlineit (scale from the scan's DPI, a grid, a card or two points), show the overlay and confirm one known dimension; photo traces stay estimates. - Photos: ask for a scale reference (ruler, grid, card) in the same plane as the feature, shot square on from a distance; size readings from photos stay estimates.
- Record each confirmed value as a named
Dimsfield whose comment gives its source, method and accuracy, and mark estimates as estimates. If the user keeps aMEASURE.mdnext to the script, treat it as the source of truth and keep the script in step with it.
Verify before reporting¶
Do all of this every time you change geometry, before telling the user the part is done:
- Build it and confirm every part is a valid solid with the volume and size you expect.
- Look at the preview render. Compare it against the user's description and photos.
- Look at cross-sections through every pocket, rib, boss, hole and mating feature. Sections show what the 3D render hides.
- Run the checks and fix every failure; mention every warning you leave. Every part gets
the overhang (with bridges), thin-feature, holes, bed-edge and gap checks automatically.
For several pieces with an
assembly(d), also run the fit check (check_fit, CLIb123d-print fit): overlaps, gaps under the clearance and screw holes that do not line up between pieces. It is not part ofcheckunless the script listsMates()inchecks(d); do that for parts that are always checked as an assembly. Moving parts (hinges, flip lids, latches, sliders): declare the motion inchecks(d),Motion(label, axis_point, axis_dir, start_deg, end_deg, against=..., min_clearance=...)orSlide(label, direction, distance, ...)onassembly(d)labels; closed and open both clear does not mean clear in between. Report the smallest clearance and its angle. - Wall check around deep cuts: wherever a cut goes deeper than the wall it starts in
(a counterbore into a boss, a pocket next to a rib, a dimple in a thin side), add a
Wallcheck that slices just past the wall and measures the material left around the cut.is_validand hole-diameter checks do not catch a 0.05 mm skin — a real print broke there. Read what each Wall and Probe says it measured (section area, how farnearis from material, the measured region; the probe box against the part's bounding box). A check that says OK while measuring the wrong place is worse than none. - Pin Wall and Probe to the part as it is used: if the part has an
assembly(d), declare them withframe="assembly"and the assembly label (Wall("lid", "XY", z, near=..., frame= "assembly")), in assembled coordinates. Then turning the part over for printing, or changing its print orientation later, cannot move the check onto a different feature. Use the defaultframe="print"only for parts without an assembly, or for properties of the print itself (a wall measured in the orientation it prints in). After changing a part's print orientation, re-check everyframe="print"coordinate. - Report: overall size (X × Y × Z), key feature dimensions, validity, the clearances and
hole compensation applied, check results, print orientation and any supports needed. On a
remote server, bring the part home first (
download_part, see Remote server) and say where it is.
Fit-test templates (before the full print)¶
A template is a quick thin print (1.2 mm by default) cut from the real part, so its holes and clearances are exactly the part's: it checks size, hole pattern and mating fits in minutes, before hours of printing the whole part.
- Offer one when the part mates with something (a board on standoffs, a lid on a box, a bracket on screws in a wall) or has a hole pattern, and the full print is long or the fit uncertain. Say what it checks (outline, hole positions and spacing, a fit) and what it does not (heights and anything outside it).
- Kinds:
slice(planeXY/XZ/YZat a Z/Y/X: the part between two planes, e.g. the top of the standoffs),face(one flat face with its holes as a plate: a mounting face),crop(the part inside a box: a corner, a clip, a boss). Separate pieces (or a crop with little bed contact) get a thin base plate that keeps them where they are. - Confirm the face or region with the user first:
list_faces(name, highlight=<id or side>)shows the face in red;make_templatereturns the_where.pngpicture, the part with the template's source in red. Ids come fromlist_faces; a side (bottom,top, ...) is the largest face facing that way. - Templates are laid flat (template face down) and checked like a part; read the notes: a template printed on its side or turned over checks hole positions and spacing, but hole sizes only where it prints the way the part does. The label is engraved where there is room, never through a feature.
- Standard fit tests go in
templates(d)soexportwrites them for every variant. - Report: the template's size, what it checks, how to use it (lay it on the board, try the screws), its findings, and where the files are.
Design review (after the print checks pass)¶
The rules and their sources are in DESIGN_GUIDE.
- Every part has a style:
STYLEinDims, else the workspacestylesetting, elsefunctional. The styles arefunctional,modern(minimal),least_cost,rugged(outdoor),soft(handheld),structural(load-bearing: brackets, mounts, clamps, hooks),organic(natural: fruit, plants, animals, figurines, shells, sculpture),decorative(vases, planters, lamp shades, ornaments) andtoy(kid-safe: small parts, breakable features, finger traps; it flags likely problems and certifies nothing [DS-K7]). For a new part, if the user has said nothing about looks, ask once; for a part that carries load, suggeststructural; for a toy or a child's thing,toy. For a natural object useorganicand start from a recipe (spine_loft,tapered_sweep,organic_blend,flat_base; thebananaexample), not from boxes, cylinders and spheres: sections along curves, blended joins, a flat base [DS-O1..O5]. For a vase, planter or lamp shade usedecorative: a vase-mode part is modeled as a solid (the slicer makes the one-line wall, no top) with every layer one closed contour, and says so withPRINT = {"vase": True, "why": ...}[DS-D1]; start from thevase_shell,twisted_loftorpatterned_surfacerecipe. The industrial look is functional withEDGES = "chamfer"and exposed standard screws. - Optional script fields:
SHOW = ["+Y", "+Z"](sides seen in use, in print orientation) limits the surface findings to those sides;UP = "+Y"is the side up in use (water traps);EDGES = "chamfer"or"fillet"is the edge language. - When
checkhas no failures, run the design review (thedesign_reviewprompt, ordesign_metricsplus the rubric): the numbers, renders of the sides seen in use, and 3–7 concrete suggestions, each citing its rule ([DS-G1]) and the numbers it would change. - The order before export, every part:
checkpasses →design_metrics(name, style=...)→suggest_orientation(name)→export. The results ofbuild_part,check,design_metricsandexportend with a Before printing block: make the calls it lists (it starts again after every edit). With thereviewsetting"warn"(default)exportsays what was skipped, also on the print sheet; with"required"it refuses until the steps are done, or the user gives a reason:export(name, skip_review="<their reason>"). A calibration coupon says"review": "exempt"in itsPRINT. - Report; do not change the part without the user's OK. A trial variant to measure a suggestion is fine; leave the script as it was unless the user agrees.
- Filament is a simple estimate (roughly ±20 %), print time and supports are rough estimates: say so, and use them to compare versions, not as a quote.
- Never suggest a proportion rule such as the golden ratio [DS-G9].
Checks reference¶
from b123d_print import Gap, Mates, Motion, Overhang, Probe, Slide, ThinFeature, Wall
def checks(d):
# Part names: a single Part returned by build() is "part" (the script's own name also works);
# build() returning {"base": ..., "lid": ...} names them.
return [
# thinnest material in the section, within `radius` of `near` (the section's 2D coords:
# XY -> (x, y), XZ -> (x, z), YZ -> (y, z)); fails below `min` (default: config min_wall)
Wall("base", "XY", d.FLOOR_T + 1.0, near=(x, y), radius=5, label="standoff pilot"),
# the same, in the coordinates of assembly(d) (by label): survives turning the part over
Wall("lid", "XY", d.LID_Z + 1.0, near=(x, y), radius=4, frame="assembly", label="screw boss"),
# downward faces > 45 deg are always reported; fail=True for parts that must print
# without supports (bridges between two walls are allowed unless bridges_ok=False)
Overhang("cover", fail=True),
# material must exist (or not) in a small box: "roof is closed", "channel is clear"
Probe("cover", (0, 10, 70), (1, 1, 0.5), expect="solid", label="roof closed"),
# automatic, listed only to change it: a living hinge is thin on purpose
ThinFeature("lid", ignore=[((0, 20, 0.25), (40, 2, 0.6))]),
# gap between two assembly parts (or part names) inside a box: the lid's sliding fit
Gap("lid", "base", min=d.CLEARANCE, max=d.CLEARANCE + 0.1, within=((0, 0, 30), (60, 60, 4))),
# opt-in: fit between the assembly's pieces (overlaps, gaps, hole alignment) inside `check`
Mates(hole_tol=0.2, ignore=[("box", "screw (stand-in)")]),
# a moving piece swept through its motion: first collision, smallest clearance, picture
Motion("lid", axis_point=(0, 30, 20), axis_dir=(-1, 0, 0), start_deg=0, end_deg=110,
against=("box",), min_clearance=d.CLEARANCE),
Slide("drawer", direction=(0, 1, 0), distance=60, against=("case",)),
]