Skip to content

Export and utilities

The project-aware build() entry point runs the mechanical export gate when a project declares joints, interfaces or fastenings. Lower-level exporters are available for callers that deliberately own their own validation flow. See file contracts for generated filenames and fields.

Fabrication

build

build(
    project,
    parts,
    directory,
    *,
    mechanical_report=None,
    validation_override=None
)

Export a selected manufacturing set with validation and manifests.

Parameters:

Name Type Description Default
project Project

Source project and mechanical declarations.

required
parts list

Selected fabrication records from project.select().

required
directory str | Path

Destination directory.

required
mechanical_report dict | None

Optional precomputed scoped report. Otherwise, projects declaring mechanics are checked automatically.

None
validation_override str | None

Explicit review reason of 3–1000 characters for exporting despite confirmed assembly failures.

None

Returns:

Type Description
dict

Build manifest also written to manifest.json, alongside quantities.json and subassemblies.json.

Confirmed mechanical failures block export unless deliberately overridden. An incomplete review remains visible and does not prove full assembly fit. A partial build's manifest contains exactly the selected set.

export_part

export_part(part, directory)

Build and validate a Part, then write print-oriented STL and native STEP.

Parameters:

Name Type Description Default
part Part | object

Part definition or selected project fabrication record.

required
directory str | Path

Destination directory, created if needed.

required

Returns:

Type Description
dict

Part metadata, measured geometry, relative filenames, and SHA-256 hashes. Mesh parts have STL only; a stale same-name STEP is removed.

This primitive does not review assembly mechanics. Use build for a project-aware export with the mechanical preflight gate and manifests.

inspect_model

inspect_model(model)

Measure geometry without applying print orientation.

Parameters:

Name Type Description Default
model object

Native Shape, Workplane, or Mesh.

required

Returns:

Type Description
dict

Representation, validity, solid count, volume in mm³, and min/max/ size bounds in mm. Mesh validity requires positive watertight geometry with consistent winding.

validate_part

validate_part(part, model)

Validate built fabrication geometry against its Part definition.

Parameters:

Name Type Description Default
part Part

Manufacturing definition.

required
model object

Geometry already in print orientation.

required

Returns:

Type Description
dict

Measurement information from inspect_model.

Raises:

Type Description
ValueError

Geometry is invalid, solid count differs from expected_solids, or its lowest Z is more than 0.001 mm from the bed.

export_stl

export_stl(model, path)

Write a native Shape or explicit Mesh to STL, creating parent directories. Native tessellation uses 0.025 mm linear and 0.08 rad angular tolerance.

run_checks

run_checks(checks, directory)

Evaluate named intersection/contact checks and write results.

Parameters:

Name Type Description Default
checks tuple

Explicit Check definitions.

required
directory str | Path

Directory for report.json and failing witness STLs.

required

Returns:

Type Description
list[dict]

Individual outcomes, including intersection volume, optional native gap, and errors. Exceptions are failed checks.

Empty input yields an empty report with a passing aggregate. This means no checks ran, not that assembly collisions were ruled out.

Installed assemblies and render assets

export_assembly

export_assembly(
    components,
    output,
    *,
    exploded=False,
    variant_selection=None
)

Write a named, colored installed STEP assembly and omission metadata.

Parameters:

Name Type Description Default
components list

Installed Components.

required
output str | Path

Destination STEP path.

required
exploded bool

Apply each Component's full explosion translation once.

False

Returns:

Type Description
Assembly

Exported native hierarchy. Mesh components are omitted and listed in the companion same-stem JSON file.

export_render_assets

export_render_assets(
    components,
    directory,
    *,
    exploded=False,
    variant_selection=None
)

Write component STLs and a scene manifest for Blender presentation.

Parameters:

Name Type Description Default
components list

Installed Components, including explicit meshes.

required
directory str | Path

Destination directory.

required
exploded bool

Set the presentation flag in the scene manifest.

False

Returns:

Type Description
dict

Manifest also written as scene.json.

STL coordinates stay installed. Explosion offsets are separate metadata applied by the renderer, avoiding a duplicated transform.

Preflight

Scoping a print set preserves the complete installed assembly as context. An explicit override records a decision to export with findings; it does not change a failed report into evidence that the model is correct.

scoped_report

scoped_report(report, assembly, parts, *, fastenings)

Scope findings to selected Parts while preserving the full installed context.

Parameters:

Name Type Description Default
report dict

Complete installed mechanical report.

required
assembly Assembly

Corresponding installed hierarchy.

required
parts list

Requested stable manufacturing Parts.

required
fastenings tuple

Declarations used to include their related hardware.

required

Returns:

Type Description
dict

Copied report with selected Part/component/hardware/fastening IDs in scope. Global reference and coverage errors remain included.

Parts with no installed instance produce an unverified coverage finding. Removing unrelated findings does not turn incomplete global coverage into a complete passing report.

reviewed_report

reviewed_report(report, validation_override=None)

Copy a mechanical report and enforce the confirmed-failure export gate.

Parameters:

Name Type Description Default
report dict

Mechanical validation report.

required
validation_override str | None

Explicit reason, 3–1000 characters after trimming, retained as accepted_with_findings metadata.

None

Returns:

Type Description
dict

Copied report, with override metadata when supplied.

Raises:

Type Description
ValueError

Override reason is invalid, or report status is fail without an explicit override.

CQ viewer

show_components

show_components(
    components,
    *,
    show_object=None,
    exploded=False,
    screenshot=None,
    interact=True
)

Display installed Components in the CQ viewer or a CQ-editor callback.

Parameters:

Name Type Description Default
components list

Installed Components.

required
show_object Callable | None

Optional CQ-editor-compatible callback. It cannot display explicit Meshes; those are reported separately.

None
exploded bool

Apply full Component explosion translations.

False
screenshot str | None

Optional output image for the standalone viewer.

None
interact bool

Keep the standalone viewer interactive.

True

Native geometry uses CadQuery's viewer; Meshes are shown as VTK actors. This function does not start CadKit Desktop or expose its MCP bridge.

Geometry builder cache

memoize_shape

memoize_shape(fn)

Cache up to 128 argument combinations of a pure geometry builder.

Parameters:

Name Type Description Default
fn Callable

Builder whose output depends only on explicit arguments.

required

Returns:

Type Description
Callable

Decorated builder with a cache_clear() method. Nested lists and dictionaries are converted to stable hashable keys.

The cached object itself is returned, not a copy. Do not mutate it. Changing module globals does not invalidate entries; pass design inputs explicitly or call cache_clear() after changing them.