# Cadquery Part

> Generate a single CadQuery part as a standalone `.py` file following all rules in `leo-monolith/resources/functions/system-messages/cad-generation.txt`. Use when the orchestrator (`cadquery-assembly`) requests one part, or when the user asks for an individual mechanical component (bracket, hub, plate, housing, shaft, etc.) modelled in CadQuery. Returns a file whose final line assigns `result` to the part workplane.

- Skill: `leoai-org/cadquery-part` (Agent Skill)
- Install (CLI): `npx skillmds@latest add leoai-org/cadquery-part`
- Raw SKILL.md: https://api.skillmd.com/api/skills/leoai-org/cadquery-part/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Web & Frontend
- Author: leoai-org (https://skillmd.com/u/leoai-org)
- Updated: 2026-09-22
- Page: https://skillmd.com/skills/leoai-org/cadquery-part

---


# CadQuery part — functional geometry only

## Purpose

Model **one manufacturable component's functional solid**: primary shape, structural voids (shells, pockets), and **mating interface geometry** (bores, spigots, slots, snap ledges) — so it assembles correctly. This pass is **not** cosmetic and **not** full DFM.

## What this pass is NOT

Do **not** add in this pass (other skills own these):

| Feature | Owner |
|---------|--------|
| Fillets, cosmetic chamfers, ribs, gussets | `cadquery-part-detailing` |
| Clearance holes, tap drills, counterbores, countersinks | `cadquery-manufacturability` |
| Vendor procurement BOM comments, engraved P/N | `cadquery-manufacturability` |
| Process draft, sheet-metal bend notes | `cadquery-manufacturability` |

A functional bracket may have a **mounting bore** (interface diameter) here; the **clearance + counterbore** for an M6 cap screw come in DFM.

## Authoritative rules

Follow `cad-generation.txt` — Critical Pitfalls, Boolean Rules, Geometry Constraints, Mechanical Interfaces (model the interface shape, not full fastener spec).

## Required file shape

```python
"""<function_name> — <one-line role>. Origin: <part-local origin rule>."""
import cadquery as cq
import math
from common import (
    HOUSING_W, M3_BORE_DIA,  # every shared dim used
)

def build_<function_name>() -> cq.Workplane:
    # ---- functional geometry only ----
    ...
    return <part_name>

result = build_<function_name>()
```

- Path: `parts/<function_name>.py`
- **Import shared dimensions from `common.py`** — never duplicate `HOUSING_W`, mate PCDs, or partner bore diameters.
- Part-local origin documented in module docstring (e.g. "center of footprint, Z=0 on bottom face").

## Inputs from orchestrator

- Function name, file path, manufacturing process guess
- Envelope + `MATE_*` constants from `common.py`
- Per-mate: what **this** part provides (socket, spigot, clearance bore, weld face, snap ledge)

## Build order (mandatory)

1. **Parameters** — only dims not already in `common.py`.
2. **Primary body** — one main extrude, revolve, or `.box()` / `.cylinder()`.
3. **Structural voids** — `.shell()`, pockets that define wall thickness (functional, not cosmetic).
4. **Interface features** — one single-extrusion tool per `cut`/`union`:
   - Bearing bores, shaft journals, keyways, drip-tray pockets, snap ledges
   - **Pilot or clearance diameter only if it is the functional interface** (e.g. bearing pocket Ø); thread/clearance pairs wait for DFM
5. **No edge treatments** — no `.fillet()` / `.chamfer()` except a **functional** shaft lead-in under 0.5 mm if required for assembly simulation
6. `return` the workplane from `build_*()`; `result = build_*()` at module level

## Design realism (functional tier)

Apply what the **function** requires — not full cosmetics:

- Housings: hollow via `.shell(-WALL_T)` on simple faces — not solid blocks
- Shafts: bearing journal steps, keyway slot if driven
- Brackets: outline + mounting **bore** locations (use `MATE_*` positions from `common.py`)
- Plates: hole **positions** via `pushPoints` or construction `rect` + `.vertices()` — diameters may be finalized in DFM

Skip ribs, gussets, and fillets — detailing adds those.

## Vendor / OTS parts

- Model **interface envelope** (bore, boss, cutout for body) in this pass.
- At most a short `# VENDOR — <category>, <key dims>` above the cut — **no SKU paragraph** until DFM.
- If a STEP file is injected, use `cq.importers.importStep('file.step')` per `cad-generation.txt`; do not redraw the catalog part.

## Anti-patterns — refuse to emit

- `rect(..., centered=False)` — use `.center(dx, dy).rect(w, h)`
- `cq.selectors.*` — string selectors only
- Compound boolean tools (`tool = a.union(b); body.cut(tool)`)
- Nested booleans in arguments
- `.translate()` on empty Workplane
- Reused rotated Workplane for multiple cuts
- Loft/sweep as boolean tools
- `extrude(0)` or revolve profile crossing axis
- Fillets/chamfers (detailing pass)
- Counterbores, tap drills, clearance pairs (DFM pass)
- Duplicating constants that exist in `common.py`

## Validation before hand-off

1. `python -c "import runpy; ns=runpy.run_path('parts/<name>.py'); bb=ns['result'].val().BoundingBox(); print(bb)"` — non-zero spans.
2. Bounding box roughly matches envelope from `common.py` (± sensible feature tolerance).
3. Hand to orchestrator for **`cadquery-render`** and **`cadquery-interference-check`** — do not render from this skill.

## Output

`parts/<function_name>.py` with `build_<function_name>()` and top-level `result`. No edits to `assembly.py` from this skill.

