L0 · DS-110

Code is the Clay: Primitives & Solids

Create a named solid of specified dimensions in real build123d and inspect it in the 3D viewer. Pass = the solid's bounding box matches the target within tolerance.

01
Challenge

Try this first — before any explanation.

The Bench opens on task 01_box. You are dropped straight into the editor + 3D viewer + autograder console with no lesson played yet. The starter makes a 10x10x10 cube with Box(10, 10, 10), but the spec card asks for a block X=52, Y=18, Z=9 mm (tolerance +/-0.1 on every axis). Edit the three numbers in Box(...) and press Run. Pyodide runs build123d on the real OpenCascade kernel, the viewer re-renders the actual solid, and the autograder reads result.bounding_box().size and reports each axis. Productive failure by design: most learners run once with a wrong number or a swapped axis, read the verdict, and self-correct.

The Bench

Write build123d Python on the real OpenCascade kernel (Pyodide + OCP.wasm). Make the spec solid, bind it to result, and see the actual part render. The autograder reads result.bounding_box().size.

length is X, width is Y, height is Z (all in mm).\n# This starter makes A box (a 10x10x10 cube), not THE spec box. Fix the three numbers.\nresult = Box(10, 10, 10)\n\nbb = result.bounding_box()\nprint(f\"measured bbox (mm): {bb.size.X:.3f} x {bb.size.Y:.3f} x {bb.size.Z:.3f}\")\nprint(f\"volume (mm^3): {result.volume:.1f}\")","task":{"bbox":[52,18,9],"tol":0.1,"volTol":50,"volume":8424},"title":"Code is the Clay: Primitives & Solids"}">
PARAMETRIC CAD

Code is the Clay: Primitives & Solids

Write build123d Python on the real OpenCascade kernel (Pyodide + OCP.wasm). Make the spec solid, bind it to result, and see the actual part render. The autograder reads result.bounding_box().size.

02
Model

The idea, built visually.

Here's a brick. You could model it by dragging a mouse around, pushing and pulling and eyeballing it. So why would an engineer write it as one line of code instead? Because every number in the code IS a dimension. In build123d you write Box(52, 18, 9): fifty-two along X, eighteen along Y, nine up Z. The code isn't a picture of the part, it's the recipe for the part, and the recipe runs on the same geometry kernel that real CAD uses. Drag with a mouse and you get about eighteen. Write Box(52, 18, 9) and you get exactly eighteen, the same solid every single time, on every machine, and because it's text a computer can grade it. One primitive, three numbers, one solid centered on the origin. Bind it to result, run it, and watch the bounding box turn green.

▣ Stage animation: Cold open: black canvas, the mono line result = Box(52, 18, 9) fades up with the question 'Why describe a shape with code instead of a mouse?'. Beat 1: a wireframe cuboid grows from the origin, X-arrow to 52, Y to 18, Z to 9, each literal pulsing the same blue as its axis as that axis draws, box centered on origin (-26..+26 in X). Beat 2: split screen MOUSE (cursor nudges a face, tooltip reads 17.96, a subtly crooked hand-dragged block) vs CODE (a crisp exact 18; the script re-runs three times stamping three identical solids, caption 'reproducible'; one edit 18 to 18.0 updates, caption 'exact, versionable, gradeable'). Beat 3: viewer UI mock, editor left, the real OCP solid shaded on the right, green BBOX OK chip, underline of Box(X, Y, Z). Outro: 4s parallax over a dark grid plane with a faint blue horizon glow.

03
Guided practice

Build it up, step by step.

Step A (worked, fully shown): the exact fix, result = Box(52, 18, 9) annotated so the three args ARE the three axis sizes in mm (length=X, width=Y, height=Z); the read-out panel prints result.bounding_box().size so the learner connects code to geometry. Step B (guided variation): spec silently swaps to X=30, Y=30, Z=6 with the hint 'same primitive, new numbers, equal X and Y make a square footprint.' Step C (centering note, productive micro-failure): the learner discovers Box is centered on the origin by default (extents run -26 to +26 in X), and the read-out confirms the centroid sits at (0,0,0); a callout previews Pos(dx,dy,dz) * Box(...) for shifting a corner to the origin, foreshadowing Module 3 frames. Step D (independent, no code shown): final gate 01_box_final, spec X=52, Y=18, Z=9 mm centered on the origin, bound to result, only the spec card and Run button remain.

04
Feedback

How the Bench grades your run.

PASS WHEN PASS prints when result is a single solid whose bounding_box().size is 52 x 18 x 9 mm within +/-0.1 on every axis (volume 8424 mm^3 within +/-50). Geometry-only grade on the real kernel, deterministic, infinite retries, no penalty.

  • result.bounding_box().size is 18.0 x 52.0 x 9.0 mm but the spec wants 52 x 18 x 9; the X and Y arguments look swapped. In Box(length, width, height) the first arg is X (52). Swap the first two numbers.
  • Z size is 8.6 mm, 0.4 mm under the 9.0 mm target (tol +/-0.1). Raise the third Box() argument to 9.
  • result.volume is 1000 mm^3 (a 10x10x10 cube); the spec solid is 52*18*9 = 8424 mm^3. Set Box(52, 18, 9).
  • X size is 5200 mm, 100x the target. build123d units are millimetres, not centimetres; use 52, not 5200.
  • No object named result was found (or it is not a build123d solid). Bind your Box(...) to result so the autograder can read its bounding box.
05
Retrieve & space

Bring back what you've already mastered.

  • Units recall (typed): build123d's length unit is ____ -> millimetres. Resurfaces the unit-confusion failure mode before it bites.
  • Predict-the-size (no running): Box(20, 8, 4) — what is the Y size of result.bounding_box() in mm? -> 8. Trains the literal-to-dimension mapping (Box length, width, height = X, Y, Z).
  • Spot-the-centering (multiple choice): Box(10, 10, 10) with no Pos() applied, where is the origin relative to the solid? -> at its center (extents -5 to +5 per axis). Pre-loads the frames intuition for Module 3, where Pos(dx,dy,dz)*Box(...) shifts a corner to the origin.
06
Mastery gate

What you must demonstrate to advance.

Pass 01_box_final: result is a single build123d solid with bounding_box().size 52 x 18 x 9 mm (+/-0.1) and volume 8424 mm^3 (+/-50), centered on the origin, AND answer retrieval cards 1-3 correctly. Proves the L0->L1 competency: render a named, dimension-correct primitive from real build123d code and read its geometry in the viewer. No time gate, infinite retries.

07
Project

How this feeds your build.

Not a capstone lesson. Feeds the course capstone (M5): the Box() primitive and the literal->dimension->bounding-box-grade habit are the atomic unit of every part the learner will design, assemble, and physics-validate later. The result-bound-solid + bounding_box grade contract established here is the exact interface the M5 autograder uses to judge a finished device.