Skip to content

Assemblies and motion

import cadkit as ck
assembly = ck.Assembly("enclosure")

An assembly graph places local Part, Purchased and nested Assembly definitions. Instances must be grounded or connected to a grounded parent; a geometry output rejects unresolved placements. Multiple fixed roots are allowed. Names identify instances, connections and ports; keep them stable when you want the app to preserve selection across rebuilds.

Assembly

The core sequence is add → fix / connect → as_project. connect places a child, while fasten adds secondary hardware between already placed parts. attach adds hardware to existing named features without assigning placement. None of these operations implicitly cuts a different part.

assembly.add(part) uses the definition's name for the instance. Use assembly.add("left-bracket", part) when naming a location or repeating the same definition. Names must be unique within the containing assembly; CadKit does not invent numeric suffixes. The keyword form add(name="left-bracket", part=part) is also supported.

An omitted display group inherits a manufactured Part's group; Purchased instances default to "Purchased". Supply group="service-parts" on add to override that instance's display grouping without changing the Part's manufacturing group. Nested leaves retain their own groups when their containing instance has no group override.

Use assembly.variant(key, ck.Variant(...)) to declare a construction choice on this assembly. Its selector appears on the installed assembly's tree row; parent assemblies compose it normally. See Variants.

Assembly

Assembly(name)

A local assembly graph resolved through explicit frames and relationships.

Parameters:

Name Type Description Default
name str

Stable assembly name without path separators.

required

Add instances, fix at least one root, and connect the remaining instances. Each instance has one placement parent. Multiple fixed roots are allowed; cycles, ungrounded instances, and conflicting placements are errors.

Geometry is built lazily by output methods. Manufacturing definitions remain local and reusable across every instance and pose.

exported_features property

exported_features

Read-only mapping of public feature names to owned feature references.

exported_components property

exported_components

Read-only mapping of public component names to selected leaf references.

add

add(
    name=None,
    part=None,
    *,
    group=None,
    color=None,
    material=None,
    explode=(0, 0, 0)
)

Add a named instance without placing it or building its geometry.

Parameters:

Name Type Description Default
name str | Part | Purchased | Assembly | None

Unique instance name, or the definition itself when using add(part).

None
part Part | Purchased | Assembly | None

Reusable definition. An omitted name defaults to its name; duplicate names are errors.

None
group str | None

Display group override. Defaults to the Part's manufacturing group or Purchased; never changes manufacturing grouping. Nested assemblies retain their leaves' display groups.

None
color tuple | None

RGB display override, each channel from 0 to 1.

None
material str | None

Rendering material override.

None
explode tuple

Presentation translation in millimetres.

(0, 0, 0)

Returns:

Type Description
Instance

Owned handle for fixing, connecting, and referencing features.

variant

variant(key, choice, *, selected=None)

Declare and resolve a choice owned by this assembly's tree row.

Use a stable project-unique key and a ck.Variant definition. During ck.Variants(builder).project(...), the requested value overrides the default. Standalone builders may supply selected explicitly. The containing project discovers the choice and its installed instance path; parent assemblies do not need to forward configuration arguments.

fix

fix(instance, *, at=Frame())

Ground an instance at an explicit local frame.

Parameters:

Name Type Description Default
instance Instance

Handle returned by this assembly's add.

required
at Frame

Placement relative to the assembly origin.

Frame()

Returns:

Type Description
Instance

The same handle, for composition in calling code.

Raises:

Type Description
ValueError

The instance is foreign or already has a placement parent.

export_port

export_port(name, ref)

Expose an internal datum for connecting this assembly as a reusable subsystem.

Parameters:

Name Type Description Default
name str

Unique public port name.

required
ref PortRef | FeatureRef

Owned instance's port or feature reference.

required

export_feature

export_feature(name, ref)

Expose an owned manufacturing feature for a containing assembly's mount.

Parameters:

Name Type Description Default
name str

Unique public feature name.

required
ref FeatureRef

Owned leaf feature or an owned nested instance's exported feature, obtained with instance.feature(name).

required

The containing assembly uses instance.feature(name) in connect, fasten or attach. Re-exporting preserves the original feature and shared mount object; its datum follows this occurrence's nested pose. Only the selected leaf participates in the resolved fastening contract. Export a port separately when only a placement datum is needed.

export_component

export_component(name, component)

Expose a selected leaf for contact contracts in a containing assembly.

Parameters:

Name Type Description Default
name str

Unique public component name.

required
component Instance | ComponentRef

Owned leaf instance, or a leaf exported by an owned nested assembly instance.

required

A containing assembly accesses this leaf through its own installed instance's component(name). Re-exporting a nested component preserves its scope. Several public names may refer to the same leaf. Whole assemblies are rejected; export attachment datums separately with export_port.

connect

connect(
    name,
    relationship,
    *,
    parent=None,
    child=None,
    through=None,
    into=None,
    fastening_name=None,
    place=True,
    via=(),
    description=""
)

Connect two instance datums and normally place the child from its parent.

Parameters:

Name Type Description Default
name str

Unique connection name.

required
relationship Rigid | Revolute | Slider | InsertMount | ThreadedMount

Motion relationship or shared mounting recipe.

required
parent PortRef | None

Parent datum for a motion relationship.

None
child PortRef | None

Child datum for a motion relationship.

None
through FeatureRef | None

Mount's clearance-side feature on the child.

None
into FeatureRef | None

Same mount object's receiver feature on the parent.

None
fastening_name str | None

Hardware identity; defaults to connection name.

None
place bool

Whether a mount connection assigns child placement. Prefer fasten() for a secondary fastening on already placed parts.

True
via tuple[FeatureRef, ...]

Middle roles covering the grip continuously. Intermediate instances need their own placement.

()
description str

Description of a motion connection.

''

Returns:

Type Description
MotionConnection | Connection

Handle usable for poses or tool access.

Parent and child datums coincide at zero motion. Rotation is in degrees about local Z; sliding is in millimetres along local Z. Mount roles must bind the exact same mount object, not merely equal recipe values.

fasten

fasten(
    name,
    mount,
    *,
    through,
    into,
    via=(),
    fastening_name=None
)

Add a mount fastening between already placed instances.

Parameters:

Name Type Description Default
name str

Unique connection name.

required
mount InsertMount | ThreadedMount

Shared recipe used by each role.

required
through FeatureRef

Outermost clearance-side feature.

required
into FeatureRef

Receiving insert or threaded feature.

required
via tuple[FeatureRef, ...]

Intermediate clamped-layer features.

()
fastening_name str | None

Optional distinct hardware identity.

None

Returns:

Type Description
Connection

Nonplacing connection. Resolution requires all role datums to coincide in the installed assembly.

attach

attach(name, recipe, **features)

Bind hardware to existing features without adding a placement edge.

Parameters:

Name Type Description Default
name str

Unique attachment and fastening name.

required
recipe CaptiveNutFastening | SetScrew

Hardware attachment recipe.

required
**features FeatureRef

through and nut references for a captive nut, or thread and stop references for a set screw. Each is an owned FeatureRef.

{}

Returns:

Type Description
Attachment

Attachment record. Features can belong to one physical part.

interface

interface(
    name,
    *,
    left,
    right,
    kind="contact",
    region=None,
    max_overlap_mm3=0,
    min_clearance_mm=0,
    max_gap_mm=None,
    description=""
)

Declare contact or clearance between two selected leaf instances.

Parameters:

Name Type Description Default
name str

Unique interface name.

required
left Instance | ComponentRef

Owned leaf instance or exported leaf anchored to an owned nested assembly instance.

required
right Instance | ComponentRef

Second distinct leaf reference.

required
kind str

contact, clearance, press_fit, threaded, or mesh.

'contact'
region Callable | None

Native overlap-region builder in this assembly's coordinates; it transforms with the declaring assembly, not independently with either moving participant.

None
max_overlap_mm3 float

Permitted overlap within the bounded region.

0
min_clearance_mm float

Required minimum separation in millimetres.

0
max_gap_mm float | None

Maximum permitted gap; contact defaults to 0.001.

None
description str

Physical intent of the interface.

''

Returns:

Type Description
Contact

Local declaration resolved into an Interface for validation.

Whole nested assemblies are not contact participants. Select their exported leaves with instance.component(name); these references follow every placement and pose of that particular nested occurrence.

access

access(
    name,
    *,
    connection,
    envelope,
    obstacles,
    at=Frame(),
    description=""
)

Check a complete tool envelope relative to a fastening's receiving datum.

Parameters:

Name Type Description Default
name str

Unique tool-access name.

required
connection Connection | str

Local mount connection handle or name.

required
envelope Callable

Zero-argument native builder for the complete swept tool solid in receiving-datum coordinates.

required
obstacles tuple[Instance, ...]

Explicit local obstacles, including whole subassemblies when appropriate.

required
at Frame

Additional placement relative to the receiving datum.

Frame()
description str

Tool and operation being checked.

''

Returns:

Type Description
ToolAccess

Declaration that follows the fastening in every pose.

Only the supplied envelope and obstacle set are checked. The library does not infer a tool path or a complete assembly sequence.

driver_access

driver_access(
    name, *, connection, diameter, length, obstacles
)

Add a straight cylindrical driver probe at every screw seat.

Parameters:

Name Type Description Default
name str

Unique tool-access name.

required
connection Connection | str

Local mount connection handle or name.

required
diameter float

Positive probe diameter in millimetres.

required
length float

Positive outward probe length in millimetres.

required
obstacles tuple[Instance, ...]

Explicit instances to check for obstruction.

required

Returns:

Type Description
ToolAccess

Access declaration extending from the screw seats along the receiving datum's outward +Z direction.

couple

couple(name, *, driver, driven, ratio, offset=0)

Derive one joint coordinate as driven = driver * ratio + offset.

Parameters:

Name Type Description Default
name str

Unique coupling name.

required
driver str | MotionConnection

Driving joint handle or scoped path.

required
driven str | MotionConnection

Joint whose coordinate is derived.

required
ratio float

Finite multiplier; units follow the two joint coordinates.

required
offset float

Finite offset in the driven joint's units.

0

Returns:

Type Description
Coupling

Coupling record. A joint can have only one driver.

name_pose

name_pose(name, positions)

Register a named set of scalar joint positions without changing the default pose.

Parameters:

Name Type Description Default
name str

Unique pose name.

required
positions dict

Motion connection handles or scoped joint paths mapped to values in degrees for revolute joints and millimetres for sliders.

required

Returns:

Type Description
Assembly

This assembly, allowing chained definitions.

pose

pose(positions)

Freeze this definition and resolve a reusable pose selection.

Parameters:

Name Type Description Default
positions dict | str

Position mapping or previously registered pose name.

required

Returns:

Type Description
AssemblyPose

Snapshot whose output methods use the selected positions. Later changes to the assembly graph do not alter the snapshot.

locations

locations(*, at=Frame(), pose=None, names='immediate')

Resolve instance locations without building geometry.

Parameters:

Name Type Description Default
at Frame

Placement of this assembly in its caller's coordinates.

Frame()
pose dict | str | None

Joint positions, named pose, or defaults.

None
names str

immediate for this assembly's direct instances, or path for every leaf keyed by its relative assembly path.

'immediate'

Returns:

Type Description
dict[str, Location]

Instance names or leaf paths mapped to native locations.

motion_graph

motion_graph(*, at=Frame(), pose=None)

Describe geometry-free viewer transforms for an immutable pose.

The graph contains column-major millimetre matrices, scalar joints, couplings and component targets. It never builds or changes part geometry.

components

components(
    *,
    at=Frame(),
    pose=None,
    include_hardware=False,
    kind=None
)

Build flattened installed Components from the resolved graph.

Parameters:

Name Type Description Default
at Frame

Placement of the assembly.

Frame()
pose dict | str | None

Joint positions or named pose.

None
include_hardware bool

Include generated fastening hardware.

False
kind str | None

Restrict leaves to manufactured or purchased.

None

Returns:

Type Description
list[Component]

Located Components in world millimetres.

models

models(*, kind=None, names='leaf', at=Frame(), pose=None)

Build models keyed by instance names or relative paths.

Parameters:

Name Type Description Default
kind str | None

manufactured, purchased, or all definitions.

None
names str

leaf for unique leaf names, or path for scoped identities.

'leaf'
at Frame

Placement of the assembly.

Frame()
pose dict | str | None

Joint positions or named pose.

None

Returns:

Type Description
dict[str, Workplane | Mesh]

Native models as Workplanes and explicit meshes as Mesh objects. Generated hardware is excluded.

Raises:

Type Description
ValueError

Leaf names are ambiguous; request names="path" instead.

fastenings

fastenings(*, at=Frame(), pose=None)

Resolve installed fastenings from this graph and its selected pose.

Parameters:

Name Type Description Default
at Frame

Placement of this assembly.

Frame()
pose dict | str | None

Joint positions or named pose.

None

Returns:

Type Description
tuple[Fastening, ...]

Stable mechanical declarations in world coordinates.

joints

joints(*, at=Frame(), pose=None)

Resolve installed joints from this graph and its selected pose.

Parameters:

Name Type Description Default
at Frame

Placement of this assembly.

Frame()
pose dict | str | None

Joint positions or named pose.

None

Returns:

Type Description
tuple[Joint, ...]

Stable mechanical declarations in world coordinates.

interfaces

interfaces(*, at=Frame(), pose=None)

Resolve installed interfaces from this graph and its selected pose.

Parameters:

Name Type Description Default
at Frame

Placement of this assembly.

Frame()
pose dict | str | None

Joint positions or named pose.

None

Returns:

Type Description
tuple[Interface, ...]

Stable mechanical declarations in world coordinates.

purchased_bom

purchased_bom()

Aggregate quantities of purchased definitions independently of pose.

Returns:

Type Description
tuple[dict, ...]

Rows keyed by definition name, supplier and SKU, containing total quantity and relative instance paths.

Each instance contributes its definition's quantity. Fastener hardware is counted separately by the hardware BOM.

as_assembly

as_assembly(
    *,
    at=Frame(),
    pose=None,
    include_hardware=True,
    kind=None
)

Build a placed cadkit._project.Assembly hierarchy.

Parameters:

Name Type Description Default
at Frame

Placement of this assembly.

Frame()
pose dict | str | None

Joint positions or named pose.

None
include_hardware bool

Include located fastening hardware.

True
kind str | None

manufactured, purchased, or all leaves.

None

Returns:

Type Description
Assembly

Hierarchy with native geometry, names, and colors.

as_cq_assembly

as_cq_assembly(
    *,
    at=Frame(),
    pose=None,
    include_hardware=True,
    kind=None
)

Build a placed cq.Assembly hierarchy.

Parameters:

Name Type Description Default
at Frame

Placement of this assembly.

Frame()
pose dict | str | None

Joint positions or named pose.

None
include_hardware bool

Include located fastening hardware.

True
kind str | None

manufactured, purchased, or all leaves.

None

Returns:

Type Description
Assembly

Hierarchy with native geometry, names, and colors.

as_project

as_project(
    *,
    parameters=(),
    checks=(),
    description="",
    pose=None,
    extra_parts=(),
    quantities=None,
    joints=(),
    interfaces=(),
    fastenings=()
)

Freeze this assembly into an inspectable, exportable Project.

Parameters:

Name Type Description Default
parameters tuple

Discoverable Parameter metadata.

()
checks tuple

Explicit Check definitions.

()
description str

Project description.

''
pose dict | str | None

Joint positions or named pose for the default view.

None
extra_parts tuple[Part, ...]

Additional manufacturing definitions, such as uninstalled coupons or variants. An installed definition may also appear here; the same object is counted once.

()
quantities dict[str, int] | None

Positive manufacturing counts by part name. Defaults to installed instance counts, or one for an uninstalled extra. Counts do not depend on the selected pose.

None
joints tuple

Additional installed mechanical declarations.

()
interfaces tuple

Additional installed contact/clearance contracts.

()
fastenings tuple

Additional installed hardware stacks. Explicit installed contracts require a static assembly; use feature-bound connections and attachments when hardware must follow motion.

()

Returns:

Type Description
Project

Snapshot with manufacturing inventory, installed tree, mechanics, and named poses. Repeated manufactured definitions contribute instance quantities; purchased components stay outside the print registry.

describe

describe()

Instance handles

Get an Instance from assembly.add(...). A leaf instance exposes its local feature() and port() references. A nested instance exposes the definition's exported ports through port(), manufacturing features through feature(), and contact participants through component(). Each reference is bound to that installed occurrence.

Instance dataclass

Instance

Handle returned by Assembly.add; use its feature and port accessors.

Instances belong to one assembly. Do not construct them directly or reuse a handle in another assembly. Reuse the underlying Part or Assembly definition.

feature

feature

Reference a named manufacturing feature owned by this instance's definition.

Parameters:

Name Type Description Default
key str

Feature name.

required

Returns:

Type Description
FeatureRef

Bound local datum and feature definition.

Raises:

Type Description
ValueError

The feature is absent or is not exported by the nested assembly.

port

port

Reference a local port or an exported nested-assembly port.

Parameters:

Name Type Description Default
key str

Port name.

required

Returns:

Type Description
PortRef

Instance-bound attachment datum.

component

component

Reference a selected leaf exported by this nested assembly instance.

Parameters:

Name Type Description Default
key str

Name declared with the nested assembly's export_component.

required

Returns:

Type Description
ComponentRef

Leaf reference scoped to this occurrence of the assembly.

Raises:

Type Description
ValueError

This is a leaf instance or the component is not exported.

Fasten across subsystems

Publish an owned manufacturing feature when a parent needs to bind a shared mount across the subsystem boundary:

unit.export_feature("mount", housing.feature("mount"))
head = machine.add("head", unit)
machine.connect("head-mount", mount,
                through=head.feature("mount"), into=arm.feature("mount"))

Both roles must use the same mount object. The exported reference retains the leaf's original feature, including its local datum, layer dimensions and manufacturing operations. It follows the installed occurrence's nested placement and pose; generated hardware, fit interfaces and driver access use that same resolved datum. Fastening participants identify only the selected leaves.

Re-export a nested feature with unit.export_feature(name, nested.feature(key)). Export names are unique; exported_features provides a read-only mapping. Use fasten when both participants already have placement parents, or attach for a feature-bound hardware recipe. Intermediate stack roles can also be exported and passed as via=. Distinct roles in one stack must identify distinct leaves, even when exported under different names. A placing connection still requires distinct immediate parent and child instances.

Secondary fastenings require all role datums to coincide in the selected pose. The viewer disables motion whose additional fastening constraints cannot be represented by the placement graph. A Python pose resolves and validates those constraints. Exporting a feature does not change or duplicate its geometry.

Contact participants across subsystems

Use unit.export_component("foot", foot_instance) to expose a selected Part or Purchased leaf. After adding the unit to a parent, unit_instance.component("foot") returns a scoped ComponentRef for use in assembly.interface(left=..., right=...). Either side can be a direct leaf owned by the declaring assembly or a component reference obtained from one of its nested instances.

Ports expose placement datums; components expose the geometry a contact or clearance declaration concerns. Exporting a component does not place it, add another occurrence or change its manufacturing definition. A higher-level unit can re-export a component reference from one of its own nested instances. Export names are unique. Multiple names may refer to the same leaf, but the two participants of an interface must resolve to distinct leaves.

References resolve through the selected pose and remain distinct when the same subsystem is reused. An interface's optional region is expressed in the declaring assembly's coordinates; it does not follow one participant's motion independently. Referencing a mesh or approximate purchased envelope preserves the geometry backend's validation limits.

See the nested-contact example for a complete runnable project.

ComponentRef dataclass

ComponentRef

An exported leaf scoped to one installed subassembly occurrence.

Obtain this with instance.component(name). Pass it to Assembly.interface or re-export it with Assembly.export_component; it is not an attachment datum. Reusing a subassembly creates distinct references for its instances.

Attributes:

Name Type Description
instance Instance

Nested assembly instance anchoring this reference.

key str

Component export name on that instance's assembly definition.

Motion relationships

Parent and child datum frames coincide at zero motion. Motion applies around or along the parent's positive Z. Coupling ratios and offsets are explicit: CadKit does not infer gear ratios, solve arbitrary loops, or prove a motion sweep free of collision.

Rigid dataclass

Rigid(kind: str = 'rigid')

A connection whose parent and child datums coincide without motion.

Parameters:

Name Type Description Default
kind str

Relationship label; retain its default value, rigid.

'rigid'

location

location(position=0)

Return the native relative Location for the given position in zero.

Revolute dataclass

Revolute(
    position: float = 0,
    limits: tuple[float, float] | None = None,
)

One rotation about the attachment frame's positive Z axis.

Parameters:

Name Type Description Default
position float

Default angle in degrees.

0
limits tuple[float, float] | None

Optional inclusive (minimum, maximum) angles in degrees.

None

Positions outside declared limits are rejected. This is a scalar placement relationship, not a general constraint solver or a collision-free motion proof.

location

location(position=None)

Return the native relative Location for the given position in degrees.

Slider dataclass

Slider(
    position: float = 0,
    limits: tuple[float, float] | None = None,
)

Bases: Revolute

One translation along the attachment frame's positive Z axis.

Parameters:

Name Type Description Default
position float

Default displacement in millimetres.

0
limits tuple[float, float] | None

Optional inclusive (minimum, maximum) displacements in millimetres.

None

location

location(position=None)

Return the native relative Location for the given position in millimetres.

Pose snapshots

AssemblyPose dataclass

AssemblyPose

Immutable pose selection over a snapshot of an authoring graph.

Obtain this with assembly.pose(positions). Its output methods forward to the matching Assembly method with the selected pose. Pass placement and filtering options as usual; supplying another pose option is rejected.

The pose object exposes locations, components, models, joints, fastenings, interfaces, as_assembly, as_cq_assembly, as_project, and describe. Their placement/filter options match the Assembly methods above; the pose itself is already selected.

Project output

as_project() captures the assembly for the CLI, desktop and exporters. Named poses become available to commands with --view. Use extra_parts for uninstalled manufacturing definitions, quantities for explicit totals, and parameters and checks for project evidence. See Project model for their semantics.

Compose reusable subsystems by passing an Assembly to add(). Export its public attachment datums with export_port() and connect the resulting instance just as you would a Part. Export contact participants with export_component() for interfaces declared by the parent. Nested placements and mechanical relationships resolve in the selected pose.

locations() returns immediate-instance transforms. Use locations(names="path") for scoped leaf transforms without building geometry, and models(names="path") when a check needs the corresponding installed shapes.

Viewer motion

Assembly.motion_graph() exports a geometry-free transform graph for the selected pose. Matrices are column-major in millimetres. Nodes contain a constant matrix, a scalar joint transform, an ordered matrix product, or an inverse; every reference points to an earlier node. Component targets identify their world-transform node and inverse captured transform. Multiply those together to obtain the display transform for already-installed meshes. Couplings derive driven coordinates before node evaluation; joint limits apply to every resolved coordinate.

Compiled joint metadata identifies parent_components and child_components. The parent is stationary relative to that joint, but may move with an upstream joint. Desktop mechanical descriptions also include each joint's moving_components, including attached descendants and generated hardware.

The graph is a placement preview, not a dynamics or collision solver. Joints with additional fastening constraints that cannot be represented by the placement graph are disabled in the viewer. Author a pose in Python to validate those arrangements.