Skip to content

Project model

import cadkit as ck

assembly = ck.Assembly("fixture")
plate = ck.Part("plate", body=plate_body, manufacture=ck.FDM("PETG"))
assembly.fix(assembly.add("plate", plate))
PROJECT = assembly.as_project()

Create a Project with Assembly.as_project(). It takes a snapshot of the authored graph for the CLI, desktop, validation and exporters. Geometry stays lazy; all coordinates use millimetres.

Manufacturing inventory

Installed manufactured definitions become project parts with quantities inferred from their instance counts. Add uninstalled coupons and variants using extra_parts=(COUPON,); override production totals with quantities={"plate": 4}. Quantity overrides must name registered definitions and be positive integers. Slicer selection can independently override a quantity to zero to omit a part from that slice job.

A Part's group, description, notes, production and expected_solids metadata travel into the compiled inventory. production=False excludes a part from build all, while explicit selection can still export it. Multiple-solid coupons should state their intended expected_solids count. Definition names are unique artifact stems; reuse the same definition for repeated instances.

parameters, checks and description are keyword arguments to as_project(). Use assembly interfaces and connections for supported mechanical requirements; custom installed contracts can be supplied with joints, interfaces and fastenings for static assemblies. These contracts use project coordinates and cannot be combined with motion edges. Declare moving hardware and interfaces on the assembly graph so they follow the selected pose.

Project inspection and output

Project

Project

Bases: Project

An assembly snapshot shared by the CLI, desktop and exporters.

Create one with Assembly.as_project(). Its manufacturing inventory contains one fabrication record per part definition, with quantities separate from display visibility and pose. Geometry builders remain lazy.

get_assembly

get_assembly

Build the installed hierarchy and matching mechanics for a named pose.

Parameters:

Name Type Description Default
view str | None

Named pose, or the project's default pose.

None
**options object

include_hardware, pose and kind selection options.

{}

get_components

get_components

Build installed components with names scoped to their assembly paths.

select

select

Select manufacturing parts by name and optional group.

Parameters:

Name Type Description Default
names tuple[str, ...]

Names to select. all selects production parts only; explicitly named optional parts are allowed. Duplicates collapse.

('all',)
group str | None

Restrict the selected set to a known manufacturing group.

None

Returns:

Type Description
list[Part]

Parts in registry order for all, otherwise requested order.

Raises:

Type Description
ValueError

Any part or group is unknown.

describe

describe

mechanical_descriptions

mechanical_descriptions

validate_mechanics

validate_mechanics

Project parts are resolved manufacturing records used by output tooling. Author geometry through Part; use its build() for local geometry and build_for_print() for print orientation and bed contact. Installed component records returned by project methods carry resolved world geometry, stable paths and definition metadata for inspection and exports.

Design inputs

Use a frozen, keyword-only dataclass derived from ck.Dimensions for a unit's configurable inputs. Declare each instance field with ck.input, and express derived dimensions as ordinary properties. Pass the same configuration to the part and assembly builders that consume it.

from dataclasses import dataclass, replace
import cadkit as ck


@dataclass(frozen=True, kw_only=True)
class BearingDimensions(ck.Dimensions):
    shaft_diameter: float = ck.input(
        default=8.0, unit="mm", description="Nominal shaft diameter", gt=0,
    )
    radial_clearance: float = ck.input(
        default=0.2, unit="mm", description="Gap between shaft and bore", ge=0,
    )
    support_span: float = ck.input(
        default=70.0, unit="mm", description="Distance between support centres", gt=0,
    )
    support_thickness: float = ck.input(
        default=12.0, unit="mm", description="Support thickness along the shaft", gt=0,
    )

    @property
    def bore_diameter(self):
        return self.shaft_diameter + 2 * self.radial_clearance

    def validate(self):
        if self.support_span <= self.support_thickness:
            raise ValueError("Support centres must be farther apart than their thickness")


dimensions = BearingDimensions()
parameters = dimensions.parameters(scope="bearing")
larger = replace(dimensions, shaft_diameter=10.0)

The field annotations are float, int, bool or str. CadKit validates their types, finite numeric values and declared gt, ge, lt and le bounds when constructing the configuration. Override validate() for relationships between fields; do not replace __post_init__, which runs the common validation. Omit default to require an input at construction. Profile tables and other structured shape data remain separate named data.

dimensions.parameters(scope="bearing") returns a tuple of Parameter records for the input fields, including their units, descriptions and source file when available. Names include the scope, such as bearing.shaft_diameter. Properties such as bore_diameter are derived values and are not independent parameters. Pass the tuple to assembly.as_project(parameters=parameters). A scope only names metadata: it does not rename parts, instances or assembly paths.

The unit string labels the value; it does not convert it. Supply lengths in millimetres and angles in the units expected by the consuming API. A configuration does not track its consumers or update geometry automatically. Use dataclasses.replace to create a validated variant, then run the builders again and compile that variant's assembly and parameter metadata together.

Dimensions

Dimensions(*args, **kwargs)

Base for validated, immutable scalar design configurations.

Subclass this with @dataclass(frozen=True, kw_only=True), annotate every instance field and declare it with cadkit.input(). Supported annotations are float, int, bool and str. Floats accept Python ints as well as floats; other types are exact, booleans are not numbers, and floats must be finite.

Override validate() for engineering relationships between inputs. Do not override __post_init__: it performs common validation before calling that hook. Ordinary properties can calculate derived dimensions without becoming inputs. Class variables are also excluded from parameter metadata.

Use dataclasses.replace(configuration, field=value) for a new validated configuration, then rebuild the parts or project from it. Dimensions has no mutable controls, dependency graph, unit conversion or geometry cache.

parameters

parameters(scope='') -> tuple[Parameter, ...]

Describe inputs using CadKit's existing Parameter records.

Parameters:

Name Type Description Default
scope str

Optional name prefix, such as bearing or left.bearing. A field called shaft_diameter becomes bearing.shaft_diameter.

''

Returns:

Type Description
tuple[Parameter, ...]

Fields in dataclass order, with current values, units, descriptions and their declaring class's source file. Source is an empty string when no existing source file is available.

Derived properties are not evaluated or published. Names retain their underscores. These records describe a configuration; they do not provide setters, live UI controls or automatic rebuilding.

validate

validate()

Check relationships between already validated inputs.

Override this method and raise ValueError for invalid engineering combinations. When extending another Dimensions subclass, call its super().validate() if its additional constraints still apply.

input

input(
    default: Any = MISSING,
    *,
    unit="",
    description="",
    gt=None,
    ge=None,
    lt=None,
    le=None
) -> Any

Declare a scalar design input on a frozen, keyword-only dataclass.

Parameters:

Name Type Description Default
default float | int | bool | str

Default Python value. Omit it to require a constructor argument.

MISSING
unit str

Display unit, such as mm or deg; no conversion is performed.

''
description str

What this input controls.

''
gt float | int | None

Exclusive lower bound for a numeric input.

None
ge float | int | None

Inclusive lower bound for a numeric input.

None
lt float | int | None

Exclusive upper bound for a numeric input.

None
le float | int | None

Inclusive upper bound for a numeric input.

None

Returns:

Type Description
Field

A standard field carrying CadKit input metadata.

Raises:

Type Description
TypeError

Units or descriptions are not strings, or bounds are not numbers.

ValueError

A bound is nonfinite or the bounds define an empty interval.

Annotate each input as float, int, bool, or str. Numeric bounds apply only to float and int fields. Values are validated when Dimensions is built; they are never coerced. Derived values belong in ordinary Python properties.

Parameter metadata

Parameter dataclass

Parameter(
    name: str,
    value: Any,
    unit: str,
    description: str,
    source: str,
    measured: bool = False,
)

A discoverable design input, recorded without changing its value.

Parameters:

Name Type Description Default
name str

Stable parameter name.

required
value Any

Current Python value; use JSON-compatible values for CLI output.

required
unit str

Display unit, such as mm, deg, or an empty string.

required
description str

What the input controls.

required
source str

Source file or other human-readable location of the input.

required
measured bool

Whether the value came from a physical measurement.

False

Parameters are metadata, not setters or live desktop controls.

Parameters describe source values and their units. They are not setters or live UI controls. Dimensions.parameters() produces them from an authored configuration. Direct ck.Parameter(...) records are also accepted by as_project(parameters=...) for measurements, imported values or metadata owned outside a Dimensions class. Use measured=True for measured values and describe their source. Edit the source and rebuild to change the design.

Checks

Check dataclass

Check(
    name: str,
    builder: Builder,
    required_contact: bool = False,
    tolerance_mm3: float = 1e-05,
    contact_pair: (
        Callable[[], tuple[Model, Model]] | None
    ) = None,
    max_gap_mm: float = 0.001,
)

An explicit forbidden-intersection or required-contact check.

Parameters:

Name Type Description Default
name str

Unique report name, also used as a collision witness filename.

required
builder Builder

Zero-argument callable returning intersection geometry or None.

required
required_contact bool

Pass when contact exists instead of requiring separation.

False
tolerance_mm3 float

Intersection volumes at or below this value count as empty.

1e-05
contact_pair Callable[[], tuple[Model, Model]] | None

Optional native shape pair for an exact surface-gap test. This detects touching surfaces even when intersection volume is zero.

None
max_gap_mm float

Maximum acceptable distance for contact_pair contact.

0.001

Builder exceptions produce failed findings. A project with no checks has no collision coverage simply because cadkit check exits successfully.

Check runs through run_checks. For automatic collision scans and hardware engagement, use mechanical validation. An empty set of custom checks cannot establish that a design has been physically validated.

Variants

Use Variants and Variant to expose discrete design choices in the desktop and CLI. Variants.project() returns an ordinary Project with its chosen inventory and mechanics; existing assembly APIs are unchanged.