compose_part_from_primitives
Create exact 3D printable parts by combining geometric primitives (cube, cylinder, sphere) with boolean operations (union, difference, intersection). Output is automatically centered on the build plate for safe printing.
Instructions
Build a functional part by composing geometric primitives with booleans.
The **CAD-aware generation path** -- instead of asking text-to-mesh AI
to guess at geometry, describe parts as a tree of primitives combined
with boolean operations. Produces exact, deterministic, functional parts.
**SAFETY DEFAULT (changed 2026-04-15):** ``center_on_bed=True`` is the
default. OpenSCAD primitives are natively centered on the model origin
(``cylinder(h,r)`` produces geometry centered on X/Y = (0,0), which
means half the geometry lives at NEGATIVE X/Y). Sending such an STL
to most FDM printers (Bambu, Prusa, Ender, Creality) — whose bed
origin is the front-left corner — causes the nozzle to drive off-bed
into the purge/wipe assembly on layer 1. This happened once on a
Bambu A1 (incident #0, 2026-04-15, nearly damaged the printer).
With ``center_on_bed=True`` the output STL is translated so it sits
centered on the build plate and its lowest point touches z=0. Set
``center_on_bed=False`` only if your downstream flow expects
origin-centered geometry (e.g. further CAD composition).
**Operation format** -- each item is either a primitive or boolean:
Primitive: ``{"type": "primitive", "shape": "<shape>",
"params": {...}, "translate": [x,y,z], "rotate": [rx,ry,rz]}``
Boolean: ``{"type": "boolean", "operation": "union|difference|intersection",
"children": [op1, op2, ...]}``
**Primitive shapes and params:**
- cube: ``{"size": [x,y,z]}`` or ``{"size": scalar}``
- cylinder: ``{"h": height, "r": radius}`` or ``{"h", "r1", "r2"}``
- sphere: ``{"r": radius}``
- cone: ``{"h": height, "r1": bottom_r, "r2": top_r}``
- torus: ``{"major_r": ring_radius, "minor_r": tube_radius}``
- wedge: ``{"width": w, "depth": d, "height": h}``
- hex_prism: ``{"r": radius, "h": height}`` -- hexagonal (for nuts)
- text: ``{"text": "string", "size": 10, "depth": 2}``
- rounded_cube: ``{"size": [x,y,z], "radius": 1}``
- pipe: ``{"h": height, "outer_r": 10, "inner_r": 8}``
Requires OpenSCAD installed on the system.
:param operations: List of operation dicts (primitive/boolean tree).
:param output_path: Output path (defaults to temp file).
:param center_on_bed: Translate output to bed-center (default True).
:param bed_x_mm: Build plate X dimension for centering (default 256).
:param bed_y_mm: Build plate Y dimension for centering (default 256).
:param printer_id: Optional supported printer model id. When
provided, printer intelligence supplies the bed size.
:returns: Dict with result path, SCAD code, triangle count, and
(if centered) ``bed_centered=True`` + applied translation.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| bed_x_mm | No | ||
| bed_y_mm | No | ||
| operations | Yes | ||
| printer_id | No | ||
| output_path | No | ||
| center_on_bed | No |