lab-hardware-cad skill (K-Dense scientific-agent-skills)

From Public Agent Wiki

What it does. Design custom laboratory hardware as parametric build123d models and export fabrication-ready STEP, STL, and DXF files - microfluidic chips and molds, optomechanical mounts and breadboard adapters, cuvette and microplate holders, tube racks, animal-behavior rigs, and 3D-printed instrument fixtures. Use when a research task needs a physical part that must mate with standardized labware, an optical table, a cage system, or a printer, CNC, or laser process. Part of K-Dense-AI/scientific-agent-skills (AI Scientist skills) (K-Dense-AI/scientific-agent-skills).

Upstream K-Dense-AI/scientific-agent-skills
Skill file skills/lab-hardware-cad/SKILL.md
License MIT
Author K-Dense Inc.
Fetched 2026-09-10

Install

  • npx skills add K-Dense-AI/scientific-agent-skills --skill lab-hardware-cad, or copy the skill folder into ~/.claude/skills/lab-hardware-cad/.
  • Raw file: curl -sL https://raw.githubusercontent.com/K-Dense-AI/scientific-agent-skills/HEAD/skills/lab-hardware-cad/SKILL.md

SKILL.md (verbatim)

name: lab-hardware-cad
description: Design custom laboratory hardware as parametric build123d models and export fabrication-ready STEP, STL, and DXF files - microfluidic chips and molds, optomechanical mounts and breadboard adapters, cuvette and microplate holders, tube racks, animal-behavior rigs, and 3D-printed instrument fixtures. Use when a research task needs a physical part that must mate with standardized labware, an optical table, a cage system, or a printer, CNC, or laser process.
license: MIT
compatibility: Python 3.10-3.14 with build123d 0.11.1 and matplotlib for snapshots. Geometry commands require build123d; the standards lookup and the interface check run on the standard library alone. No network access needed.
allowed-tools: Read Write Edit Bash Glob Grep
metadata:
  version: "1.3"
  skill-author: K-Dense Inc.
  last-reviewed: "2026-08-15"
  build123d-version: "0.11.1"

Lab Hardware CAD

Design physical research hardware as parametric Python source, export STEP as the authoritative artifact, and verify the result both numerically and visually before anything is fabricated.

The hard part of lab hardware is almost never the geometry. It is that the part must mate with equipment whose dimensions are fixed by a published standard or a vendor drawing. A holder that is 0.5 mm too wide does not fit the plate reader; a channel with the wrong aspect ratio collapses during bonding; a mount whose bolt pattern is 25.4 mm instead of 25.0 mm will not reach the optical table. This skill exists to keep those numbers correct and checked.

When to use

Use for any request to design, model, or fabricate a physical part for a lab: chip, mold, mount, adapter, holder, rack, bracket, enclosure, jig, fixture, arena, or maze. Also use to inspect or modify an existing STEP file.

Do not use for finite-element analysis, computational fluid dynamics, molecular structure, or scientific plotting. Those are different skills.

Setup

uv venv --python 3.12 .venv-labcad
uv pip install --python .venv-labcad/bin/python "build123d==0.11.1" "matplotlib>=3.8"

build123d 0.11.1 requires Python >=3.10,<3.15 and pulls in the OpenCascade kernel through cadquery-ocp-novtk. The wheel is large; install once per project and reuse it.

All bundled scripts take --help. check.py standards runs without build123d installed.

Model files are executed, not parsed. gen.py, check.py, and snapshot.py import a *_model.py and call its build(), which runs arbitrary Python in the current environment. That is inherent to parametric CAD — the source is the design. Only run model files authored in this session or supplied by the user from a trusted location. If a model came from the internet, a shared drive, or an untrusted colleague, read it before running it and say that you did.

Required workflow

Follow these steps in order. Steps 5 and 6 are not optional, and step 6 is not waived by step 5 passing.

1. Route to a device family

Read the request, classify it, and load exactly one family reference. Do not load all four — they are long, and mixing conventions between families is a common source of error.

If the part is Load
A chip, mold, channel network, flow cell, gasket, or anything with fluid ports references/microfluidics.md
A mount, post, breadboard adapter, cage-system part, filter or sample holder in a beam path references/optomechanics.md
An adapter, insert, rack, or holder for plates, cuvettes, tubes, slides, or dishes references/labware-adapters.md
An arena, maze, head-fixation part, spout, tether, or extrusion-mounted enclosure for animal work references/behavior-rigs.md

If the part genuinely spans two families — a microfluidic chip that bolts to an optical table — load the family that owns the critical interface, then read only the interface section of the second. State in your response which family you routed to.

2. Establish the interface dimensions before any geometry

Every part has at least one mating interface. Before writing code, write down for each interface:

  • the source of the dimension: a published standard, a vendor drawing, or a user measurement;
  • the nominal value and tolerance;
  • the clearance or interference you intend, and why.

Look the number up in assets/standards.json or the family reference. Never write an interface dimension from memory. If the number is not in the standards file or the reference, ask the user for the vendor drawing or the measurement rather than guessing. A guessed interface dimension is the single most expensive failure mode in this skill.

A feature that must receive a standardised component is sized against that component's maximum material condition — nominal plus its plus-tolerance — and only then given clearance. Sized from nominal instead, it fits only the smaller half of conforming parts.

python scripts/check.py standards --list
python scripts/check.py standards --show slas-microplate-footprint

The bundled standard IDs (exact strings; do not guess variants): slas-microplate-footprint, slas-microplate-height, slas-microplate-flange, slas-well-positions-96, slas-well-positions-384, slas-well-positions-1536, cuvette-standard-10mm, optical-breadboard-metric, optical-breadboard-imperial, cage-system-30mm, sm1-lens-tube-thread.

If the part mates with nothing in this list, that is common and fine: declare no interfaces, and name every interface dimension with its source (user spec, vendor drawing, measurement) as unchecked in the report. Never declare against an unrelated standard to fill the gap — a fabricated declaration is worse than an honest "nobody checked this".

3. Choose the process before choosing the geometry

Read references/fabrication-limits.md. Process determines minimum wall, minimum feature, achievable tolerance, and whether the part survives autoclaving or contact with your solvent. FDM cannot hold ±0.05 mm; SLA resin is generally not safe for cell contact without post-cure and testing. Record the process and material in the model docstring.

4. Author a parametric model

Write <part>_model.py. The source is the authoritative artifact — never hand-edit an exported STEP file, and never regenerate from a mesh.

Requirements:

  • Every dimension that a user might change is a module-level named constant with units in the name: bore_d_mm, wall_t_mm, post_h_mm. No bare numbers in the body except 0, 1, and 2.
  • Expose build() -> Part. gen.py calls it.
  • Group parameters into an INTERFACE block (dimensions fixed by a standard, annotated with the standard ID) and a DESIGN block (dimensions you are free to choose).
  • Derive every computed dimension inside a function, never at module level, so --param overrides actually reach it.
  • Declare an interfaces() function returning the dimensions the part must fit, each with its standard ID and intent. This is what makes the interface machine-checkable in step 5. intent is "envelope" when the feature must accept any conforming part (a pocket, bore, or slot — checked one-sided at maximum material condition plus your clearance) and "match" when this part must itself conform (symmetric band). clearance is the total intended clearance in mm and must be non-negative. Declare only dimensions that constrain this part's mating features — a property of the mating equipment (a table's edge border, a typical plate thickness) is not an interface of yours. If no bundled standard applies, return [].
  • Declare a checks() function of go/no-go gauges measured from the built solid: a clear region for everything that must pass through or fit in (screw shafts, beam corridors, the mating part at maximum material condition dropping into its pocket), a material region for everything that must remain (a ridge, a ledge, a screw seat), and a bbox_* bound for every size limit the user stated. Map every geometric requirement in the request to one entry; these catch the errors that is_valid, the bounding box, and declared numbers cannot see. gen.py runs them on every generation and fails the build when one fails. Schema and worked examples: references/build123d-patterns.md.
  • Put the process, material, and every interface source in the module docstring.
"""SLAS microplate carrier for a custom stage insert.

Process: FDM, PETG, 0.2 mm layer.  Tolerance budget +/-0.3 mm.
Interfaces:
  - Plate pocket: ANSI/SLAS 1-2004 (R2012) footprint 127.76 x 85.48 mm, +/-0.25.
  - Stage bolts: user-measured, 40.0 mm centres (drawing in docs/stage.pdf).
"""
from build123d import *

# --- INTERFACE (fixed by standard; do not tune) ---
plate_l_mm = 127.76   # ANSI/SLAS 1-2004 nominal
plate_w_mm = 85.48    # ANSI/SLAS 1-2004 nominal
plate_tol_mm = 0.25   # ANSI/SLAS 1-2004; the pocket is sized to nominal + this
# --- DESIGN (free) ---
pocket_clearance_mm = 0.40   # per-side; FDM, see fabrication-limits.md
wall_t_mm = 3.0
floor_t_mm = 2.5
body_h_mm = 12.0


def pocket_mm() -> tuple[float, float]:
    """Pocket at the plate's maximum material condition plus clearance per side.

    A pocket sized from nominal jams on roughly half of conforming plates.
    """
    growth = plate_tol_mm + 2 * pocket_clearance_mm
    return plate_l_mm + growth, plate_w_mm + growth


def interfaces() -> list[dict]:
    """What this part must fit. `check.py interfaces` verifies every entry."""
    pocket_l, pocket_w = pocket_mm()
    return [
        {"feature": "plate pocket length", "standard": "slas-microplate-footprint",
         "dimension": "footprint_length", "value": pocket_l,
         "intent": "envelope", "clearance": 2 * pocket_clearance_mm},
        {"feature": "plate pocket width", "standard": "slas-microplate-footprint",
         "dimension": "footprint_width", "value": pocket_w,
         "intent": "envelope", "clearance": 2 * pocket_clearance_mm},
    ]


def checks() -> list[dict]:
    """Gauges measured from the built solid. Sized from the REQUIREMENT's numbers
    (plate MMC, the user's height limit), not from the pocket parameters, so a
    wrong parameter cannot shrink the gauge to match the wrong geometry."""
    depth = body_h_mm - floor_t_mm
    return [
        {"feature": "plate at MMC drops into the pocket",
         "clear": {"box": (plate_l_mm + plate_tol_mm, plate_w_mm + plate_tol_mm, depth),
                   "at": [(0.0, 0.0, floor_t_mm + depth / 2)]}},
        {"feature": "under 15 mm for the stage", "bbox_z": {"max": 15.0}},
    ]


def build() -> Part:
    pocket_l, pocket_w = pocket_mm()
    with BuildPart() as carrier:
        Box(pocket_l + 2 * wall_t_mm, pocket_w + 2 * wall_t_mm, body_h_mm,
            align=(Align.CENTER, Align.CENTER, Align.MIN))
        with Locations((0, 0, floor_t_mm)):
            Box(pocket_l, pocket_w, body_h_mm, mode=Mode.SUBTRACT,
                align=(Align.CENTER, Align.CENTER, Align.MIN))
    return carrier.part

See references/build123d-patterns.md for the builder-vs-algebra choice, the interfaces() contract, sketching, selectors, fillets, and threaded-insert bores.

5. Generate and run the checks

python scripts/gen.py carrier_model.py --outdir out/
python scripts/check.py facts out/carrier.step
python scripts/check.py interfaces out/carrier.manifest.json
python scripts/check.py geometry out/carrier.step --model carrier_model.py

gen.py also evaluates the model's checks() gauges against the solid it just built, prints each PASS/FAIL, records them in the manifest, and exits non-zero on a failure — so a part that violates its own declared geometry never silently becomes an artifact. check.py geometry re-runs the same gauges against the exported STEP, which is the authoritative artifact.

out/ is a scratch convention, not a requirement. When the user asked for deliverables in a specific place, generate there (--outdir .) or copy the STEP, manifest, and DXF to it before finishing — a deliverable that exists only inside out/ has not been delivered.

gen.py writes carrier.step (authoritative), carrier.stl (mesh preview and printing), and carrier.manifest.json recording the source hash, resolved parameters, declared interfaces, library versions, and measured bounding box, volume, and validity. The manifest is the provenance record — keep it with the artifact.

check.py facts reports is_valid, bounding box, volume, surface area, centre of mass, and solid count. A part that reports is_valid: false is broken geometry; fix the source before going further.

check.py interfaces evaluates every entry the model declared against the standards database and exits non-zero on failure. Be clear about what it does and does not verify: it checks the declared numbers — catching a transcribed dimension, the wrong standard, and nominal-instead-of-MMC sizing — but it never measures the built geometry, and a value computed from the same constants it is checked against passes with zero headroom by construction. Do not cite it as evidence the geometry is right; facts and the snapshot are the geometry checks. An empty declaration list passes: a part that mates with nothing in the bundled database has nothing to declare, and its interface dimensions are instead named as unchecked in the report.

Use interfaces rather than check.py fit for anything internal — a pocket, bore, or slot does not appear in the part's outer bounding box, which is what fit measures. Reach for fit only to check one number by hand (--value footprint_length=128.81), or when the part's own outline is the interface, such as a gasket cut to a plate footprint.

For assemblies, check that parts do not interfere:

python scripts/check.py clearance out/carrier.step out/lid.step --min 0.3

6. Snapshot and actually look at it

python scripts/snapshot.py out/carrier.step --out out/carrier.png

Then read the PNG. This step is mandatory after every generation and every modification. Deterministic checks passing is not a reason to skip it: is_valid and a correct bounding box are both fully consistent with a pocket cut on the wrong face, a boss placed outside the body, or a fillet that ate a feature. Those errors are obvious in a picture and invisible in the numbers.

Know the render's limits too. A feature much smaller than the frame — a 0.3 mm mold ridge on a 40 mm part, a counterbore step on a plate — may not be decidable from the views at all. Do not report seeing something the image cannot resolve; that is worse than not looking. For such features the skill has instruments: check.py bores prints every cylindrical face (diameter, axis, position, span, sweep) so you can reconcile the drilling against the model's intent, and check.py probe answers a one-off "is this region clear / is material present here" without editing the model. Cite the measured numbers; report from the picture only what the picture actually shows.

The six views are true orthographic projections, and the outlines are the model's real edges drawn without hidden-line removal. So a circle visible "through" material is a bore on the far side, not a window — the part is not transparent. Read it that way rather than reporting a hole that is not there.

State in your response what you saw in the snapshot, not merely that you generated one.

7. Repair through the source

If any check fails, edit the parameters or the model code, rerun gen.py, and rerun both step 5 and step 6. Never patch the STEP.

8. Report before fabrication

Work through references/validation.md and give the user: the process and material, every interface dimension with its source and tolerance, the clearances chosen, what the snapshot showed, and any check that did not pass.

Flag explicitly every interface the automatic check could not cover — a vendor drawing, a user measurement, a standard not in the bundled database. check.py interfaces reports only what the model declared against a known standard, so silence there is not confirmation; a dimension nobody could check has to be named as such.

Units

build123d is unitless internally and everything in this skill is millimetres and degrees. export_step is called with Unit.MM. Imperial hardware appears throughout optomechanics (1/4-20 screws, 1 inch grids, SM1 threads); convert to millimetres in a single named constant at the point of definition and never mix systems inside an expression. 1 inch is exactly 25.4 mm, and a 25 mm metric optical grid is not interchangeable with a 1 inch imperial grid — the error accumulates to 1.6 mm over four holes.

Tolerances and fits

A nominal dimension is not a fit. Every mating dimension needs a deliberate clearance chosen from the process tolerance in references/fabrication-limits.md. Common defaults, per side:

Fit FDM SLA CNC
Free-sliding (plate in a pocket) 0.40 mm 0.20 mm 0.10 mm
Located but removable 0.25 mm 0.10 mm 0.05 mm
Press / interference -0.05 mm -0.03 mm -0.02 mm

These are starting points for a first article, not guarantees. Say so when you report them, and recommend printing a test coupon of the critical interface before committing to a full part.

Scientific caveats

  • Material compatibility governs. A geometrically perfect part in the wrong polymer fails in service: autoclave cycles distort PLA, many solvents craze acrylic, and uncured SLA resin is cytotoxic. Check references/fabrication-limits.md before recommending a material for anything contacting cells, tissue, solvents, or heat.
  • Optical parts have non-geometric requirements. Autofluorescence, surface roughness, and stray-light scatter are not visible in a STEP file. Black resin is not automatically low-scatter.
  • Vendor labware varies. The SLAS standards fix the plate footprint but not well geometry, skirt profile, or lid fit, and consumable tubes differ between suppliers. Design to the standard where one exists; otherwise require a measurement.
  • A passing bounding box is not a passing part. fit checks the dimensions it is given. It cannot see a missing feature, and it does not replace the snapshot.

References

File Contents
references/microfluidics.md Channel cross-sections and aspect ratios, mold vs chip polarity, minimum features by process, port and tubing interfaces, bonding lands, dead volume
references/optomechanics.md Breadboard grids and screw clearances, post and pedestal heights, 30 mm cage geometry, SM lens-tube threads, beam height
references/labware-adapters.md ANSI/SLAS 1-4 microplate dimensions, cuvettes, tubes, slides, dishes, deck and stage constraints
references/behavior-rigs.md Arena and maze geometry, head-fixation interfaces, spouts and ports, T-slot extrusion, cleaning and durability
references/fabrication-limits.md Process tolerances, minimum walls and features, clearance and thread inserts, materials, autoclave and solvent and biocompatibility
references/validation.md Pre-fabrication checklist and the failure modes each item catches
references/build123d-patterns.md build123d 0.11.1 API cookbook: builder vs algebra, sketches, selectors, joints, exports

Scripts

Command Purpose
gen.py <model.py> --outdir DIR Run build(), export STEP and STL, write the provenance manifest
gen.py <model.py> --dxf [--dxf-z MM] Also slice a 2D DXF profile for laser cutting (default plane: mid-height)
check.py facts <step> Validity, bounding box, volume, area, centre of mass, solid count
check.py interfaces <manifest|model.py> Check every declared interface number against its standard; non-zero exit on failure
check.py geometry <model.py|step --model M> Evaluate the model's checks() gauges against the built solid — measured, not declared
check.py probe <step> --cyl D|--box X,Y,Z --at ... One ad-hoc gauge: is this region clear of material, or filled with it
check.py bores <step> Census of every cylindrical face: diameter, axis, position, span, sweep
check.py fit --standard ID --value DIM=MM Check one dimension by hand, or a part whose outer envelope is the interface
check.py clearance <a> <b> --min MM Minimum distance between two solids; detects interference
check.py standards [--list|--show ID] Browse the bundled standards data (standard library only)
snapshot.py <step> --out PNG Six-view orthographic and isometric render for visual review

All commands accept --json for machine-readable output and write progress to stderr. check.py standards, and check.py interfaces on a manifest, run without build123d installed.

Citing Scientific Agent Skills

This skill is part of Scientific Agent Skills by K-Dense. If it materially contributed to a manuscript, report, presentation, or code release, add the paper to the references or software section and tell the user you did so:

Kassis, T., Agarwal, V., He, Y., Patel, D., & Brueckner, A. M. (2026). Scientific Agent Skills: A Library of Procedural Knowledge for Research Agents. arXiv:2609.00065. https://doi.org/10.48550/arXiv.2609.00065

Always cite the current version. The DOI and https://arxiv.org/abs/2609.00065 resolve to the latest arXiv version, so never append a version suffix such as v1. When network access is available, fetch https://arxiv.org/abs/2609.00065 (or http://export.arxiv.org/api/query?id_list=2609.00065) before writing the reference and take the author list, year, and version from that record. If the record lists a journal reference or publisher DOI, cite the published version instead.

Other files in this skill

references/behavior-rigs.md (verbatim)

Animal-behavior rigs and enclosures

Arenas, mazes, head-fixation hardware, spouts and ports, and the extrusion frames that carry them.

Dimensions come from the protocol, not from this file

Behavioral apparatus dimensions are not standardised. They are set by the published protocol the experiment replicates, and they differ between species, strains, ages, and labs. An elevated plus maze sized for rats is wrong for mice; an open field sized from one paper will not reproduce another paper's results.

Ask which protocol or paper the rig replicates, and take the dimensions from it. If the user does not have one, say plainly that the geometry is a design choice affecting comparability, and get their sign-off on the numbers before modelling. Do not supply "standard" maze dimensions from memory — there is no such standard, and a plausible-looking wrong number is worse here than an admitted gap, because it silently breaks comparison with prior work.

What this file does cover is the engineering that is common across rigs.

Regulatory and welfare context

Any apparatus that contacts animals falls under the institution's approved protocol. Before fabrication:

  • The design must be consistent with the approved IACUC (or local equivalent) protocol. A geometry change — a narrower arm, a different head-plate, a new restraint — may require an amendment. Flag this; it is not the modeller's call to make.
  • Materials must be non-toxic and non-irritant, including after repeated cleaning.
  • No entrapment or pinch geometry: no gaps that can catch a limb, tail, or head; no wedge- shaped gaps that narrow into a trap. Break sharp edges everywhere an animal can reach.
  • Anything load-bearing over an animal needs a real margin, not a printed part at minimum wall.

Raise these actively rather than waiting to be asked.

Materials and cleaning

This dominates material choice, and it eliminates most of the obvious options:

  • Cleaning agents are the constraint. Ethanol (70%) crazes many plastics; quaternary ammonium and chlorine dioxide disinfectants attack others; autoclaving distorts anything with a low glass transition temperature. PLA in particular softens well below autoclave temperature and should be treated as single-use.
  • Porosity carries odour. FDM parts are porous by construction, hold odour cues between animals, and cannot be reliably disinfected. Odour is a genuine confound in behavior work. Prefer a non-porous process, or seal the surface, or treat FDM parts as consumable and per-cohort.
  • Chew resistance. Rodents will chew anything reachable. Printed polymer at an exposed edge will be destroyed and, worse, ingested. Put metal, glass, or a hard sacrificial edge wherever an animal can bite, and keep printed material out of reach where possible.
  • Uncured resin is cytotoxic and an irritant. SLA parts that contact animals need full post- cure and thorough washing. See references/fabrication-limits.md.

Video tracking and optics

Most rigs are recorded, and the geometry either helps or fights the tracking:

  • Contrast: match the surface to the animal's coat so the tracker can segment it. Matte white or light grey floors for dark animals, matte dark for albino. Matte, not gloss — specular highlights are tracked as objects.
  • Avoid shadow-casting geometry near the floor. Deep walls at low camera angles create shadow bands that trackers segment as the animal.
  • Infrared: if illumination is IR, remember that many "opaque" black plastics transmit IR, and that IR-transparent floors change the apparent image. Verify with the actual camera, not by assumption.
  • Leave a clear, unobstructed camera line to the whole arena, and model the camera mount as part of the rig so the field of view is checked before fabrication, not after.

T-slot extrusion frames

Most rigs are built on aluminium extrusion. The critical fact: slot width is not implied by profile size.

Profile Common slot widths Typical fastener
20 x 20 mm 5 mm or 6 mm depending on series M4 or M5 T-nut
30 x 30 mm 8 mm typical M6 T-nut
40 x 40 mm 8 mm or 10 mm depending on series M6 or M8 T-nut

A 20 mm profile from one supplier takes a 6 mm slot nut; from another, 5 mm. Measure the slot, or get the part number. A bracket modelled for the wrong slot is scrap.

Design notes:

  • Slot the bracket's mounting features along the extrusion axis. That is the whole point of extrusion — position is continuously adjustable, and a fixed hole throws that away.
  • Extrusion faces are the datum. Design brackets to register flat against a face and, where possible, into the slot, so the part cannot rotate under load.
  • Printed brackets carrying a camera or a heavy component should be treated as prototypes. Polymer creeps under sustained load and the camera will slowly droop out of alignment.

Head fixation

The highest-consequence geometry in this file, and entirely lab-specific.

  • The head-plate or head-post interface must come from the actual implant the lab uses, as a drawing or a measurement. There is no standard. Get the part.
  • The kinematic requirement is to constrain the implant repeatably and without play, with clamping force that does not deflect the plate. Play translates directly into imaging or recording motion artefact.
  • Fixation hardware must be quick to release, both for routine handling and in an emergency.
  • Printed clamps flex. For any part carrying head-fixation load, recommend machined metal and present the printed version as a fit-check prototype only. Say this explicitly — it is a welfare issue as well as a data-quality one.

Spouts, ports, and reward delivery

  • Spout material must be non-toxic and cleanable; stainless steel tubing is the usual choice, held by a printed carrier that never itself contacts the animal's mouth.
  • Position is a calibrated experimental variable. Make spout position adjustable and readable, and record it in the manifest, so it can be reproduced across sessions and animals.
  • Model the reward line's dead volume — the delay between valve and spout is an experimental parameter. See the dead-volume formula in references/microfluidics.md.
  • If lick detection is capacitive, keep conductive material away from the sensing element and give the wire a defined, strain-relieved route in the model.

Checks to run

python scripts/gen.py arena_model.py --outdir out/
python scripts/check.py facts out/arena.step
python scripts/check.py clearance out/arena.step out/camera_mount.step --min 1.0
python scripts/snapshot.py out/arena.step --out out/arena.png

Confirm in the snapshot:

  1. No gap an animal can get a limb, tail, or head into.
  2. All animal-reachable edges broken; no sharp corners.
  3. Camera has an unobstructed view of the whole floor.
  4. Extrusion mounting features are slotted, and on the faces you can actually reach with a tool.
  5. Nothing printed sits where it will be chewed.

Sources

Deliberately none for dimensions. Arena, maze, and head-fixation geometry must come from the protocol being replicated or from the physical implant, not from a general reference. The material, cleaning, tracking, and extrusion guidance above is general engineering practice.

references/build123d-patterns.md (verbatim)

build123d 0.11.1 patterns

An API cookbook for the geometry this skill actually needs. Every snippet here was run against build123d 0.11.1 on Python 3.12.

Builder mode or algebra mode

build123d offers two equivalent APIs.

# Builder mode: a context manager collects operations. mode= controls the boolean.
with BuildPart() as ex:
    Box(80.0, 60.0, 10.0)
    Cylinder(radius=11.0, height=10.0, mode=Mode.SUBTRACT)
part = ex.part

# Algebra mode: plain objects and operators.
part = Box(80.0, 60.0, 10.0) - Cylinder(radius=11.0, height=10.0)

Use builder mode for parts in this skill. Selectors (ex.edges(), ex.faces()) read naturally from the builder, which is what you need for fillets and for placing features on found faces. Algebra mode is a good fit for short, purely constructive shapes.

Do not mix the two styles inside one build().

The model file contract

gen.py imports the module, calls build(), and then reads interfaces(). Parameters must be module-level so they can be overridden with --param.

"""One-line description of the part.

Process: SLA, tough resin.  Orientation: bore axis vertical.
Interfaces:
  - Rod bores: 30 mm cage system, Thorlabs ER series (cage-system-30mm).
"""
from build123d import *

# --- INTERFACE (fixed; do not tune) ---
rod_spacing_mm = 30.0     # cage-system-30mm
rod_bore_d_mm = 6.4       # rod_diameter 6.0 + 2 x 0.20 SLA free-sliding (fabrication-limits.md)
# --- DESIGN (free) ---
plate_t_mm = 8.9
aperture_d_mm = 25.4


def interfaces() -> list[dict]:
    return [
        {"feature": "cage rod bore spacing", "standard": "cage-system-30mm",
         "dimension": "rod_spacing", "value": rod_spacing_mm, "intent": "match"},
        {"feature": "cage rod bore diameter", "standard": "cage-system-30mm",
         "dimension": "rod_diameter", "value": rod_bore_d_mm,
         "intent": "envelope", "clearance": 0.4},
    ]


def build() -> Part:
    half = rod_spacing_mm / 2
    with BuildPart() as plate:
        Box(rod_spacing_mm + 12.0, rod_spacing_mm + 12.0, plate_t_mm)
        with Locations((half, half), (-half, half), (half, -half), (-half, -half)):
            Hole(radius=rod_bore_d_mm / 2)
        Hole(radius=aperture_d_mm / 2)
    return plate.part

Declaring interfaces

Most lab-hardware interfaces are internal features — a pocket, a bore, a slot — and none of them appear in the part's outer bounding box. So check.py fit cannot find them by measuring the STEP, and hand-copying the number into --value reintroduces exactly the transcription error the skill exists to prevent. Declaring them closes the loop: gen.py records the declaration in the manifest, and check.py interfaces verifies every entry.

Each entry needs standard, dimension, and value; feature, intent, and clearance are optional:

Key Meaning
standard ID from check.py standards --list
dimension a dimension name inside that standard
value the number this model computed, in mm
feature human label for the check output (default: the dimension name)
intent match if this part must itself conform; envelope if the feature must accept any conforming part (default: match)
clearance total intended clearance in mm, both sides (default: 0)

Write interfaces() as a function, and compute derived dimensions inside functions. A module-level INTERFACES = [...] list is also accepted, but it is evaluated at import — before --param is applied — so any value derived from an overridden parameter is recorded wrong. The same applies to the geometry: derive inside build() or a helper, never at module level.

# Wrong: --param plate_tol_mm=0 silently leaves pocket_l_mm at the old value
pocket_l_mm = plate_l_mm + plate_tol_mm + 2 * pocket_clearance_mm

# Right: recomputed on every call, so overrides land
def pocket_l_mm() -> float:
    return plate_l_mm + plate_tol_mm + 2 * pocket_clearance_mm

gen.py warns when it sees a static INTERFACES list together with --param.

Declaring geometry checks

interfaces() compares declared numbers against the standards database; it never touches the solid. checks() is its measured counterpart: a list of go/no-go gauges evaluated by boolean intersection against the part build() actually produced. gen.py runs them on every generation and fails the build if one fails; check.py geometry re-runs them against an exported STEP.

The principle: every geometric requirement in the request maps to one entry. Something must pass through (a screw, a beam, a probe) → a clear region. Something must fit into a void (a plate into a pocket) → a clear box the size of the mating part at maximum material condition. Something must remain (a ridge, a ledge, a screw seat) → a material region. A stated size limit → a bbox_* bound. These are exactly the errors is_valid, the bounding box, and a declared-number check cannot see.

def checks() -> list[dict]:
    top = plate_t_mm / 2
    return [
        # a clear region: no material may intrude (screw shafts, through the part)
        {"feature": "M6 screws pass all four bores",
         "clear": {"cylinder": 6.0, "axis": "z", "at": bolt_xy()}},
        # a keep-out with an explicit span (a beam corridor along x at height z)
        {"feature": "beam clear at 15 mm above the bench",
         "clear": {"cylinder": 5.0, "axis": "x", "at": [(0.0, 15.0)]}},
        # a gauge part that must drop into a pocket: the mating part at MMC
        {"feature": "SLAS plate at MMC drops into the pocket",
         "clear": {"box": (128.01, 85.73, pocket_depth_mm()),
                   "at": [(0.0, 0.0, floor_t_mm + pocket_depth_mm() / 2)]}},
        # a counterbore that really is a counterbore: recess open, seat present.
        # The second entry is what catches a recess that punched through.
        {"feature": "counterbore recess open at the top",
         "clear": {"cylinder": cbore_d_mm - 0.2, "axis": "z", "at": bolt_xy(),
                   "span": (top - cbore_depth_mm + 0.1, top + 0.1)}},
        {"feature": "screw seat present below the recess",
         "material": {"cylinder": cbore_d_mm - 0.2, "axis": "z", "at": bolt_xy(),
                      "span": (-top + 0.1, top - cbore_depth_mm - 0.1)},
         "min_mm3": 50.0},
        # a user-stated hard limit, measured from the solid
        {"feature": "clears the objective turret", "bbox_z": {"max": 15.0}},
    ]

Semantics:

Key Meaning
clear / material region that must contain no material / must contain material
{"cylinder": DIA, "axis": "x"|"y"|"z", "at": [(a, b), ...], "span": (lo, hi)} at is 2D in the plane perpendicular to the axis — axis z: (x, y); axis x: (y, z); axis y: (x, z). Omit span to run through the whole part
{"box": (dx, dy, dz), "at": [(x, y, z), ...]} axis-aligned box gauges centred at each position
tol_mm3 / min_mm3 pass thresholds per position (both default 0.01)
bbox_xbbox_z, bbox_min/mid/max {"min": mm, "max": mm} bounds on the measured bounding box

Size the gauges from the same named constants as the geometry only when the requirement is relational (the recess sits above the seat). When the requirement is absolute — a mating part's MMC, a user's height limit, a beam position — write the gauge from the requirement's own numbers, so a wrong parameter cannot shrink the gauge to match the wrong geometry.

For a one-off question without editing the model, check.py probe runs a single gauge from the command line, and check.py bores prints a census of every cylindrical face (diameter, axis, position, span, sweep) to reconcile against the model's intent.

Positioning

Locations places the objects created inside it. It is the workhorse for bolt patterns.

with Locations((10.0, 0.0), (-10.0, 0.0)):        # two positions on the current plane
    Hole(radius=3.3)

with Locations((0.0, 0.0, floor_t_mm)):           # offset in z
    Box(10.0, 10.0, 5.0, mode=Mode.SUBTRACT)

with GridLocations(9.0, 9.0, 12, 8):              # x spacing, y spacing, x count, y count
    Hole(radius=1.5)

GridLocations centres the grid on the origin. A microplate well grid is dimensioned from the plate corner instead, so compute absolute positions and pass them to Locations:

a1_x_mm, a1_y_mm, pitch_mm = 14.38, 11.24, 9.0    # slas-well-positions-96
origin_x = -plate_l_mm / 2
origin_y = plate_w_mm / 2
wells = [
    (origin_x + a1_x_mm + pitch_mm * col, origin_y - a1_y_mm - pitch_mm * row)
    for row in range(8) for col in range(12)
]
with Locations(*wells):
    Hole(radius=well_clear_d_mm / 2)

Alignment

By default objects are centred on the origin. align moves the datum, which is usually what you want for a pocket that starts at a floor:

Box(x, y, z, align=(Align.CENTER, Align.CENTER, Align.MIN))   # sits on z = 0
Box(x, y, z, align=(Align.MIN, Align.MIN, Align.MIN))         # corner at the origin

Getting this wrong is the classic "pocket cut through the floor" bug, and it is exactly what the snapshot catches.

Holes

Hole cuts through the whole part; CounterBoreHole and CounterSinkHole add a head recess.

CounterBoreHole cuts downward from the workplane it is placed on, with the recess at that plane. On a centred Box the default workplane is the mid-height of the part, so a 2-tuple location buries the screw seat inside the plate — or, on a thin plate, lets the recess swallow the top entirely, leaving a straight bore the screw head falls through. Place it on the top face (or give the location an explicit z at the top):

with BuildPart() as plate:
    Box(60.0, 60.0, 10.0)                              # spans z = -5 .. +5
    top = plate.faces().sort_by(Axis.Z)[-1]
    with Locations(top):
        with Locations((20.0, 20.0)):
            CounterBoreHole(radius=6.6 / 2, counter_bore_radius=11.0 / 2,
                            counter_bore_depth=6.5)

Size counter_bore_depth from the screw head height, not from habit: an M6 socket head cap screw head is 6.0 mm tall, a 1/4-20 head 6.35 mm (screw_head_height in the breadboard standards). A 4 mm counterbore leaves either head 2 mm proud — do not call that flush. After generating, confirm in the snapshot (or a section) that the recess is at the top face and the seat ledge exists; both failure modes here pass is_valid and the bounding box untouched.

Remember that printed holes come out undersize — see references/fabrication-limits.md.

Selectors

Selectors find edges and faces to fillet, chamfer, or build on. The three you need:

part.edges().filter_by(Axis.Z)              # keep edges parallel to Z (the vertical corners)
part.edges().group_by(Axis.Z)[-1]           # the group with the highest Z (the top edges)
part.faces().sort_by(Axis.Z)[-1]            # the single highest face
part.edges().filter_by(GeomType.CIRCLE)     # only circular edges

filter_by keeps everything matching. group_by partitions into lists ordered by the key, so [-1] is the last group and [0] the first. sort_by orders individual items.

with BuildPart() as ex:
    Box(80.0, 60.0, 10.0)
    chamfer(ex.edges().group_by(Axis.Z)[-1], length=4.0)   # chamfer the top face edges
    fillet(ex.edges().filter_by(Axis.Z), radius=5.0)       # round the vertical corners

These broad selectors are only safe on a part that is still a plain box. Once the part has pockets, bores, notches, or micro-relief, filter_by(Axis.Z) and group_by(Axis.Z)[-1] also select the edges of those features, and the fillet either throws a kernel error (Failed creating a fillet, BRep_API: command not done) or — worse — succeeds and silently eats a wall or a 0.3 mm ridge. Both happen in practice. So:

  • Fillet or chamfer the outer body before adding internal features, or filter the selection down deliberately (by position, length, or GeomType) so only the intended edges remain.
  • Bound the radius with part.max_fillet(edges) when the nearby geometry is tight — it returns the largest radius the kernel can actually build on that edge set.
  • Make every fillet/chamfer radius a named parameter, and on a kernel failure back the value off rather than fighting the selector.
  • Then check the snapshot: a consumed feature is obvious in the picture and invisible in is_valid.

Sketch then extrude

For a profile that is not a primitive, sketch it and extrude:

with BuildPart() as bracket:
    with BuildSketch() as profile:
        Rectangle(40.0, 20.0)
        with Locations((15.0, 0.0)):
            Circle(radius=4.0, mode=Mode.SUBTRACT)
    extrude(amount=6.0)

This is also the route to a laser-cut DXF: the sketch is the cut profile.

Exports

gen.py handles these, but for reference:

export_step(part, "part.step", unit=Unit.MM)                 # authoritative
export_stl(part, "part.stl", tolerance=1e-3, angular_tolerance=0.1)

# 2D profile for laser cutting. section() is a module-level operation, NOT a
# method on the shape -- part.section(...) raises AttributeError.
from build123d.exporters import ColorIndex   # NOT exported by `from build123d import *`

profile = section(part, Plane.XY.offset(z_mm), mode=Mode.PRIVATE)
profile = profile.moved(Location((0, 0, -z_mm)))   # back to z = 0, or the DXF writer
                                                   # warns about a non-planar shape
exporter = ExportDXF(unit=Unit.MM)
exporter.add_layer("CUT", color=ColorIndex.RED)    # laser shops key power/speed to layers
exporter.add_shape(profile, layer="CUT")
exporter.write("part.dxf")

Cut the section through material, not at z = 0: a part modelled sitting on the build plate has only a degenerate face there. gen.py --dxf defaults to the part's mid-height and takes --dxf-z to override.

STEP preserves exact BREP geometry; STL is a triangulated approximation. Always keep STEP as the source of truth and regenerate meshes from it, never the reverse.

Measuring in code

Useful for asserting an interface inside the model itself:

bbox = part.bounding_box()
print(bbox.size.X, bbox.size.Y, bbox.size.Z)
print(part.volume, part.area)
print(part.is_valid)          # a property in 0.11.1, not a method
print(part.center(CenterOf.MASS))

is_valid being a property rather than a method is a real difference from older releases and from some documentation. Access it without parentheses.

Things that bite

  • is_valid is a property. part.is_valid() raises TypeError: 'bool' object is not callable.
  • section() is a module-level operation, not a method. part.section(Plane.XY) raises AttributeError. Call section(part, plane, mode=Mode.PRIVATE).
  • intersect() returns a ShapeList with no .volume; the & operator returns a Solid that has one. check.py clearance handles both.
  • Never name a script inspect.py in a directory that lands on sys.path. It shadows the standard library inspect module, which breaks typing_extensions and therefore build123d itself. This is why the bundled script is check.py.
  • Builder objects are not parts. Return builder.part, not the builder.
  • Mode.SUBTRACT needs an existing body. Subtracting from an empty context does nothing silently.
  • A swept or extruded profile is centred on its path/plane unless you align it. Sweeping a Rectangle(w, h) along a path on a surface leaves half the profile below the surface — a "0.3 mm ridge" that is really 0.15 mm proud. Pass align= (and an explicit x_dir on the profile plane) so the profile sits where you think it does, then measure the result.
  • Curve has no .length. Sum the edges instead: sum(e.length for e in curve.edges()).
  • The boolean of touching or disjoint solids is empty, not an error. Depending on the path you get None, an empty Compound, or a ShapeList with no .volume — guard before reading .volume in any interference check.
  • ColorIndex and LineType live in build123d.exporters, not in the top-level namespace; from build123d import * does not bring them in, and add_layer(color=1) fails.
  • The OpenCascade kernel raises assorted exception types. Catch broadly around boolean operations and report the failure rather than letting a traceback escape.

Sources

references/fabrication-limits.md (verbatim)

Fabrication limits, tolerances, and materials

Read this before finalising any geometry. Process determines what geometry is possible; material determines whether the part survives the lab.

Process tolerances

Achievable tolerance and minimum feature size, as planning figures. Every number here depends on the specific machine, material, and operator. Use them to choose a process and to size a first article, then verify with a test coupon.

Process Typical tolerance Min wall Min feature Notes
FDM ±0.3 mm (often worse over 100 mm) 1.2 mm (3 x 0.4 mm nozzle) ~0.8 mm Anisotropic: much weaker across layers. Porous.
SLA / DLP ±0.1 mm 0.8 mm ~0.3 mm Better surface and detail. Resin choice dominates properties.
SLS (nylon) ±0.2 mm 0.8 mm ~0.5 mm Isotropic, no supports, slightly porous surface.
CNC milling ±0.05 mm or better 0.8 mm in metal Set by tool diameter Internal corners carry the tool radius — you cannot mill a sharp internal corner.
Laser cutting ±0.1 mm n/a Kerf ~0.1-0.3 mm 2D only. Edge taper on thick stock. Kerf offset must be applied.

Two consequences that catch people:

  • Holes print undersize on both FDM and SLA. A 6.0 mm modelled hole typically measures under 6.0 mm. Oversize functional bores, or plan to ream them.
  • Internal corners cannot be sharp in milling. If a milled pocket must accept a square part, add corner relief cuts. (For a part with rounded corners the tool radius is harmless as long as it stays at or below the part's minimum corner radius — see the corner-radius rule in references/labware-adapters.md.)

Laser cutting

  • Kerf direction is fixed by the physics, so get it right in the handover. The beam removes a strip of width k (~0.1–0.3 mm) centred on the drawn line. Cutting on the line therefore makes holes and internal cutouts come out oversize by ~k, and the part's outer outline undersize by ~k. Say which convention the DXF uses (on-the-line is the default assumption) and let the shop offset, or offset the geometry yourself and say so — never both.
  • Put cut geometry on a named layer (one layer per operation: CUT, ENGRAVE). Shops key power and speed to layer or colour; geometry on layer 0 forces them to guess.
  • Cut order matters: internal features before the outer outline, or the part shifts once it is freed from the sheet.
  • Sheet stock is not its nominal thickness. "3 mm" acrylic commonly runs ~2.8–3.2 mm; slots sized for nominal will be loose or tight. For solvent-welded joints prefer cast acrylic over extruded — cleaner cut edge, less vapour crazing — and remember alcohols craze acrylic either way (see Chemical, below).
  • Laser-cut edges are sharp and slightly tapered; call out deburring or flame-polishing for anything handled or animal-facing.

Fits and clearances

Nominal dimensions do not produce fits. Choose a clearance deliberately, per side:

Fit FDM SLA CNC
Free-sliding (a plate dropping into a pocket) 0.40 mm 0.20 mm 0.10 mm
Located but removable by hand 0.25 mm 0.10 mm 0.05 mm
Press / interference -0.05 mm -0.03 mm -0.02 mm

Then remember the other part has tolerance too. When mating to a standardised component, design the receiving feature against the component's maximum material condition, not its nominal — a pocket sized from nominal fits only the smaller half of conforming parts. This is what intent: "envelope" enforces. Declare it in the model and check the manifest:

python scripts/check.py interfaces out/part.manifest.json

Or check a single number by hand:

python scripts/check.py fit --standard slas-microplate-footprint \
  --intent envelope --clearance 0.8 --value footprint_length=128.81

Threads and inserts

Printed threads are usually a mistake. Layer resolution is comparable to the thread pitch, so printed threads are weak, dimensionally unreliable, and shed particles.

In descending order of preference:

  1. Heat-set threaded inserts — the standard solution for printed parts. Model a straight bore to the insert manufacturer's specified diameter (it varies by insert; get the datasheet) and provide enough surrounding wall, typically at least 2 mm.
  2. Clearance hole plus a captive nut in a hex pocket. Reliable and cheap.
  3. Tapping the printed material directly — acceptable for light, infrequently-assembled joints.
  4. Printing the thread — only for coarse threads (roughly M6 and above), never for fine threads like the 0.635 mm pitch SM1 (see references/optomechanics.md).

Orientation and anisotropy

For FDM especially, orientation is a design decision, not a printing detail:

  • Parts are substantially weaker across layers than along them. Orient so that load runs along layers, and state the intended orientation in the model docstring.
  • Overhangs beyond roughly 45 degrees need support, and supported surfaces come out rough and dimensionally poor. If a surface is a sealing or mating face, orient it so it is not supported.
  • Holes printed with their axis vertical are round; printed horizontally they come out with a drooped top. Teardrop or chamfer horizontal holes that must stay round.
  • Every enclosed cavity needs a drain path in resin printing. See references/microfluidics.md.

Materials

Thermal

Material Approximate service limit Autoclave (121 °C)?
PLA ~50-60 °C No — distorts well below autoclave temperature
PETG ~70-80 °C No
ABS / ASA ~90-100 °C Marginal, generally no
Polypropylene ~100 °C Marginal
Nylon (SLS) ~120-160 °C Sometimes; verify per grade
PEEK >250 °C Yes
Stainless steel, aluminium, glass High Yes

Assume a printed part is not autoclavable unless it is a verified high-temperature material. Offer chemical or gas sterilisation as the alternative, and check that against the solvent notes below.

Chemical

  • Acrylic (PMMA) crazes on contact with alcohols, including 70% ethanol — a serious problem in a lab that disinfects everything with ethanol.
  • Polycarbonate is attacked by many solvents and by some alkaline cleaners.
  • PLA hydrolyses; it degrades in warm, wet, or repeatedly-cleaned service.
  • PP, PTFE, PEEK have broad chemical resistance and are the safe choices for solvent contact.

Always ask what the part will be cleaned with, not just what it will contain. Cleaning agent compatibility is more often the failure than the sample.

Biocompatibility

  • Uncured SLA resin is cytotoxic. Even nominally biocompatible resins require the manufacturer's full post-cure and wash protocol, and leachables can still affect sensitive cell assays.
  • For anything contacting cells, tissue, or animals: prefer glass, medical-grade polymer, or PTFE for the contact surface, and use the printed part as a holder that does not touch the sample.
  • "Biocompatible" on a resin datasheet refers to a specific certified process and application. It does not transfer to your printer, your cure schedule, or your assay. Say this rather than implying a printed part is cell-safe.

Optical

  • Printed and milled surfaces scatter; they are not optical surfaces.
  • Most printed resins autofluoresce, often strongly, which contaminates fluorescence readouts.
  • Black is not automatically non-reflective.
  • Where an optical surface is needed, use glass or a bonded film and model the holder around it.

Cost and lead-time reality

Mention these when recommending a process: FDM is hours and pennies; SLA is hours and modest cost; SLS and CNC are typically outsourced with days of lead time and much higher cost. A design that needs ±0.05 mm has committed the user to CNC — flag that trade before they discover it at quoting.

Before fabrication

Work through references/validation.md.

Back to K-Dense-AI/scientific-agent-skills (AI Scientist skills) or Agent skills.