Skip to content

Parts and frames

import cadkit as ck

Definitions own local geometry and manufacturing intent; an assembly supplies installed placement. Part.build() returns local geometry. Part.build_for_print() applies the declared fabrication orientation and moves the result onto the bed.

Bodies can be native CadQuery shapes or explicit cadkit.geometry.Mesh values. Native-only manufacturing features, finishing callbacks and sheet validation require native bodies. Mesh parts retain their provenance and export STL, with explicit omission reporting for STEP.

Manufacturing groups, notes, production inclusion and expected solid counts belong to the Part. See Project inventory for uninstalled coupons, variants and quantity overrides.

Part dataclass

Part(
    name: str,
    body: Callable,
    manufacture: FDM | LaserCut,
    features: Mapping[str, Feature] = dict(),
    ports: Mapping[str, Frame] = dict(),
    finalize: Callable | None = None,
    *,
    group: str = "parts",
    description: str = "",
    production: bool = True,
    expected_solids: int | None = 1,
    notes: str = ""
)

An immutable local definition with owned features and attachment ports.

Parameters:

Name Type Description Default
name str

Stable artifact name using letters, numbers, _ and -.

required
body Callable

Zero-argument builder returning a valid native solid, explicit native compound or cadkit.geometry.Mesh. Mesh definitions support placement and fabrication, but not native feature operations.

required
manufacture FDM | LaserCut

Explicit FDM or LaserCut manufacturing metadata.

required
features Mapping[str, Feature]

Named feature objects, applied in mapping insertion order.

dict()
ports Mapping[str, Frame]

Named local Frames for composition; these do not cut geometry.

dict()
finalize Callable | None

Optional callable receiving the featured Shape and returning a native result, for operations such as final edge finishing.

None
group str

Manufacturing group used by selection and quantity reports.

'parts'
description str

Short description of the manufactured part.

''
production bool

Include this definition in the default all fabrication set.

True
expected_solids int | None

Positive expected solid count, or None for a variable count.

1
notes str

Markdown manufacturing notes.

''

Mappings are copied and exposed read-only. Building starts with a copy of the body. Assembly placement never changes this reusable definition.

build

build()

Build in design coordinates. No assembly or print pose enters here.

build_for_print

build_for_print()

Build fabrication geometry, applying its print transform and placing it on Z=0.

Returns:

Type Description
Shape | Mesh

Fabrication geometry. This never changes installed placement or the result of build().

describe

describe()

Return manufacturing, feature, port, and operation metadata without building the body.

Feature protocol

Built-in manufacturing features and mount roles satisfy this protocol. A custom feature must return valid native geometry and describe its own manufacturing intent.

Feature

Bases: Protocol

Protocol for a named operation owned by one declarative Part.

Attributes:

Name Type Description
at Frame

Local manufacturing datum.

apply(body) returns a native CadQuery solid. describe() returns JSON-compatible feature metadata, optionally including manufacturing operations. Features run in mapping insertion order.

Manufacturing processes

FDM("PETG", print_rotation=(90, 0, 0)) applies explicit X/Y/Z angles for fabrication. When the design-to-fabrication transform is already known, use FDM("PETG", print_frame=ck.Frame(...)) instead. A print_frame cannot be combined with nonzero print_rotation. Both paths move the final lowest Z point onto the bed without changing installed assembly geometry.

FDM dataclass

FDM(
    material: str,
    print_rotation: tuple = (0, 0, 0),
    *,
    print_frame: Frame | None = None
)

Manufacturing metadata for a fused-deposition printed part.

Parameters:

Name Type Description Default
material str

Explicit material name; use unspecified when unknown.

required
print_rotation tuple

Finite X, Y, Z angles in degrees. Applied only by the fabrication builder, never during local assembly placement.

(0, 0, 0)
print_frame Frame | None

Optional rigid transform from design to fabrication coordinates. Used instead of a nonzero print_rotation. The result is translated onto Z=0 after this transform; X and Y offsets are preserved.

None

LaserCut dataclass

LaserCut(material: str, thickness: float)

A native blank cut from explicitly dimensioned sheet stock.

Parameters:

Name Type Description Default
material str

Sheet material name; use unspecified when unknown.

required
thickness float

Positive sheet thickness in millimetres, along local Z.

required

Validation compares the final body's Z extent with thickness. It does not prove constant cross-section or generate a machine-ready cutting toolpath.

validate

validate(body)

Purchased components

Purchased dataclass

Purchased(
    name: str,
    body: Callable,
    ports: Mapping[str, Frame] = dict(),
    features: Mapping = dict(),
    description: str = "",
    supplier: str = "",
    sku: str = "",
    representation: str = "envelope",
    quantity: int = 1,
)

A supplied component with local geometry and attachment datums.

Parameters:

Name Type Description Default
name str

Stable definition name.

required
body Callable

Zero-argument builder returning a valid native solid, native compound, or explicit cadkit.geometry.Mesh.

required
ports Mapping[str, Frame]

Named local Frames.

dict()
features Mapping

Explicit feature operations. Use supplied=True mount roles for already present supplier geometry; other features modify the body.

dict()
description str

Human-readable component description.

''
supplier str

Supplier name for the purchased BOM.

''
sku str

Supplier identifier for the purchased BOM.

''
representation str

envelope for approximate geometry or detailed.

'envelope'
quantity int

Positive supplier quantity represented by each assembly instance.

1

Purchased objects are not exported as manufactured Parts by as_project(). An envelope does not establish exact supplier fit.

build

build()

Build a local body and apply owned native features, retaining its representation.

describe

describe()

Frame

A Frame specifies orientation with two perpendicular axes, rather than Euler angles. Use Frame(origin=(0, 0, 10), z=(0, 0, -1)) for a downward-facing entry at Z=10. A frame is a datum; it does not itself move or cut the body.

Frame dataclass

Frame(
    origin: tuple = (0, 0, 0),
    z: tuple = (0, 0, 1),
    x: tuple = (1, 0, 0),
)

An orthonormal local datum in millimetres.

Parameters:

Name Type Description Default
origin tuple

XYZ position in millimetres.

(0, 0, 0)
z tuple

Positive local Z direction; normalized on construction.

(0, 0, 1)
x tuple

Positive local X direction; normalized and required perpendicular to Z.

(1, 0, 0)

Local Y follows the right-handed CadQuery plane convention. All coordinates must be finite. Manufacturing features and mounts assign different meanings to Z; consult the feature or mount reference before reusing a datum.

location property

location

Return the equivalent native CadQuery Location.

from_location classmethod

from_location(location)

Convert a native CadQuery Location into an explicit Frame.

Parameters:

Name Type Description Default
location Location

Rigid translation and rotation.

required

Returns:

Type Description
Frame

Origin and orthonormal axes of the location.

describe

describe()

Patterns

Patterns live in a feature's local XY plane. For a rectangular four-hole pattern, for example:

corners = ck.PointPattern(((-20, -12), (20, -12), (20, 12), (-20, 12)))

PointPattern dataclass

PointPattern(
    points: tuple[tuple[float, float], ...] = ((0, 0),)
)

Explicit sites in a feature's local XY plane.

Parameters:

Name Type Description Default
points tuple[tuple[float, float], ...]

Nonempty, distinct (x, y) pairs in millimetres. The default is one site at the datum origin.

((0, 0),)

PolarPattern dataclass

PolarPattern(radius: float, angles: tuple[float, ...])

Distinct sites on a circle in a feature's local XY plane.

Parameters:

Name Type Description Default
radius float

Positive pattern radius in millimetres.

required
angles tuple[float, ...]

Nonempty tuple of finite angles in degrees, measured from +X toward +Y. Angles equivalent modulo 360 are rejected as duplicates.

required

points property

points

Return local (x, y) sites in millimetres in the supplied angle order.