2. Make the shapes a project
CadQuery builds the solids. CadKit gives the solids names, manufacturing information and an installed arrangement that the CLI, desktop and agent tools can all read.
Add named parts
Keep the dimension constants, box_body() and lid_body() from chapter 1.
Remove its final if __name__ == "__main__" export block. After the builders,
add these part definitions:
import cadkit as ck
BOX = ck.Part("box", box_body, manufacture=ck.FDM("PETG"))
LID = ck.Part("lid", lid_body, manufacture=ck.FDM("PETG"))
A ck.Part is a definition: a name, a builder and manufacturing information.
ck.FDM("PETG") records the intended process and material. It does not change
the shape or supply printer settings.
Arrange the parts
After the two definitions, add the assembly:
DESIGN = ck.Assembly("enclosure")
box = DESIGN.add("box", BOX, color=(0.32, 0.58, 0.72))
lid = DESIGN.add("lid", LID, color=(0.86, 0.70, 0.40), explode=(0, 0, 20))
DESIGN.fix(box)
DESIGN.fix(lid)
PROJECT = DESIGN.as_project()
A ck.Assembly contains instances of those definitions. Here it has one box
and one lid. fix places each instance at the default frame, so the coordinates
you wrote in chapter 1 are also their installed coordinates. This is enough for
two loose parts. In chapter 4, a fastening connection will place the lid instead.
The explode vector is a presentation offset for exploded views. It does not
move the installed lid or change exported manufacturing geometry.
Finally, as_project() compiles the assembly into a cadkit.Project. Assigning it
to PROJECT makes the file importable by the CLI and desktop. It captures the
design at that point, so keep that line after your assembly declarations.
Your file is now ready to run. To check your edits or start at this chapter,
expand the complete example and copy it into enclosure.py.
Complete project: enclosure.py
"""Chapter 2: named parts and an inspectable CadKit Project."""
import cadquery as cq
WIDTH = 80
DEPTH = 50
HEIGHT = 20
WALL = 2.4
LID_THICKNESS = 3
def box_body():
# The rim is Z=0; the box extends down from it.
outside = cq.Workplane("XY").rect(WIDTH, DEPTH).extrude(-HEIGHT)
cavity = (cq.Workplane("XY").rect(WIDTH - 2 * WALL, DEPTH - 2 * WALL)
.extrude(-(HEIGHT - WALL)))
return outside.cut(cavity)
def lid_body():
return cq.Workplane("XY").rect(WIDTH, DEPTH).extrude(LID_THICKNESS)
import cadkit as ck
BOX = ck.Part("box", box_body, manufacture=ck.FDM("PETG"))
LID = ck.Part("lid", lid_body, manufacture=ck.FDM("PETG"))
DESIGN = ck.Assembly("enclosure")
box = DESIGN.add("box", BOX, color=(0.32, 0.58, 0.72))
lid = DESIGN.add("lid", LID, color=(0.86, 0.70, 0.40), explode=(0, 0, 20))
DESIGN.fix(box)
DESIGN.fix(lid)
PROJECT = DESIGN.as_project()
Read it from the terminal
The output should contain box and lid, each with material PETG and
quantity 1. enclosure:PROJECT means “import enclosure.py and read its
PROJECT attribute.”
You can also inspect the project description without building the solids:
Look for the same two names and their manufacturing information in the JSON. Those stable names are how you will select parts for exports and agent work.
Open it in CadKit Desktop
Install the app on Linux or macOS if you have not already:
On Linux, run:
"$HOME/.local/bin/cadkit-desktop" \
--project-dir "$PWD" --project enclosure:PROJECT \
--python "$PWD/.venv/bin/python"
On macOS, run:
"$HOME/Applications/CadKit.app/Contents/MacOS/CadKit" \
--project-dir "$PWD" --project enclosure:PROJECT \
--python "$PWD/.venv/bin/python"
The explicit Python path uses the same environment as your CLI. Keep the app
open while working through the tutorial. You should see the closed enclosure
and box and lid in its assembly tree.
Hide the lid with its eye button. The hollow interior should now be visible.
Show it again, then select the box. Its inspector should identify the box
part. Try changing HEIGHT to 24 in your editor: after saving, the app
rebuilds the geometry while retaining the view. Restore 20 before continuing.
Complete example · ← Make the shapes · Next: inspect and export →

