Tutorial

Build 3 models hands-on.

You’ve grasped the basics in “Getting Started.” Now let’s get hands-on and build some models.


Lesson 1: Building an Enclosure

We’ll make a case for an electronics board. Learn the golden pattern of CAD modeling – “create → select → modify” – by doing it yourself.

The finished model

box 100 60 40
 | faces >Z | shell 2
 | edges =Z | fillet 3
 | edges <Z | fillet 1
 | faces right
 | circle 4 | cut
 | faces left
 | points (grid 2 4 10)
 | hole 3
✎ Edit

Don’t try to take it all in at once. We’ll build it up one step at a time.

Step 1: Create a box and hollow it out

box 100 60 40
 | faces >Z | shell 2
✎ Edit

faces >Z selects the top face, and shell 2 hollows the body to a wall thickness of 2mm. The selected face is removed, leaving an open-top box.

Step 2: Round the edges

box 100 60 40
 | faces >Z | shell 2
 | edges =Z | fillet 3
 | edges <Z | fillet 1
✎ Edit

edges =Z selects vertical edges parallel to the Z axis. Round them with a generous R3. edges <Z selects bottom edges. A subtle R1.

Step 3: Cut a connector hole in the right face

box 100 60 40
 | faces >Z | shell 2
 | edges =Z | fillet 3
 | edges <Z | fillet 1
 | faces right | circle 4 | cut
✎ Edit

faces right selects the right face, entering 2D sketch mode directly. circle 4 | cut makes a through-hole.

By the way, if you just need a single hole at the center of a face, hole also works:

 | faces right | hole 4
✎ Edit

hole can be used directly from a face selection, so it’s shorter than circle ... | cut. However, if you need to offset the hole from the face center, circle + move + cut is more flexible.

Step 4: Add screw holes on the left face

box 100 60 40
 | faces >Z | shell 2
 | edges =Z | fillet 3
 | edges <Z | fillet 1
 | faces right
 | circle 4 | cut
 | faces left
 | points (grid 2 4 10)
 | hole 3
✎ Edit

faces left moves to the left face. points (grid 2 4 10) places points in a 2x4 grid (the third argument is pitch = center-to-center distance), and hole 3 drills all the holes at once.

After selecting a face, you can also write grid 2 4 10 directly, omitting points:

 | faces left
 | grid 2 4 10
 | hole 3
✎ Edit

Done. A decent case, written in code you can read in 30 seconds.


Lesson 2: Making it parametric

The enclosure from Lesson 1 has hardcoded dimensions. Let’s make it reusable with variables and functions.

Managing dimensions with variables

$w = 100
$h = 60
$d = 40
$wall = 2

box $w $h $d
 | faces >Z | shell $wall
 | edges =Z | fillet 3
 | edges <Z | fillet 1
✎ Edit

When you need a different size, just change the numbers at the top.

Turning it into a function

def enclosure($w, $h, $d, $wall) =
  box $w $h $d
   | faces >Z | shell $wall
   | edges =Z | fillet 3
   | edges <Z | fillet 1

enclosure 100 60 40 2
✎ Edit

def defines a function. The body is the pipeline after =.

Placing variations side by side

def enclosure($w, $h, $d, $wall) =
  box $w $h $d
   | faces >Z | shell $wall
   | edges =Z | fillet 3
   | edges <Z | fillet 1

enclosure 100 60 40 2
enclosure 60 40 30 1.5 at:120 0
✎ Edit

Use at: to offset the position and place different sizes side by side. A first step toward parametric design.


Lesson 3: Combining parts

In real designs, you build parts separately and assemble them. Using a mount plate as an example, let’s learn how to combine parts.

The finished model

def plate($size) =
  box $size $size 3
   | fillet 1
   | faces top
   | points (polar 4 $size/3)
   | hole 4

$base = box 100 100 5
 | fillet 2
 | faces top | union plate 40 at:0 0
 | faces top | union plate 40 at:40 0
 | faces top
 | circle 4 | cut
✎ Edit

Step 1: Define the mount plate

def plate($size) =
  box $size $size 3
   | fillet 1
   | faces top
   | points (polar 4 $size/3)
   | hole 4
✎ Edit

A square plate with rounded edges and 4 bolt holes arranged in a circle. You can use calculations with arguments like size/3. You can also write polar 4 $size/3 without points after a face selection (polar/grid are implicitly interpreted as points in that context).

Step 2: Mount them on the base

$base = box 100 100 5
 | fillet 2
 | faces top | union plate 40 at:0 0
 | faces top | union plate 40 at:40 0
✎ Edit

union plate 40 at:0 0 merges a plate onto the top face. at: specifies the position.

Step 3: Add a center hole

$base = box 100 100 5
 | fillet 2
 | faces top | union plate 40 at:0 0
 | faces top | union plate 40 at:40 0
 | faces top
 | circle 4 | cut
✎ Edit

Finally, select the top face and cut a through-hole at the center. Since you can draw 2D primitives directly from a face selection, workplane is unnecessary.


Tips: Trying more primitives

So far we’ve focused on box and cylinder, but there are other useful primitives.

Cones and tori

cone 15 5 30            # frustum (vase-like shape)
cone 10 0 20            # full cone

torus 20 3              # donut-shaped ring
torus 20 3 | diff box 40 40 10   # cut in half for a D-ring
✎ Edit

Creating symmetric shapes with mirror

Build just one half and mirror it to easily create symmetric parts.

box 40 60 10
 | diff cylinder 5 10 at:10 15
 | mirror "X"
✎ Edit

"X" mirrors across the YZ plane, "Y" across the XZ plane, "Z" across the XY plane.

Creating smooth paths with spline

spline creates a smooth curve through control points. Combine it with sweep to make pipes and rails.

spline [(0,0,0), (20,10,10), (40,0,20)] | sweep (circle 2)
✎ Edit

Next Steps