Skip to content

Primitives

Primitives are the basic building blocks in CodeCAD. They represent simple 3D shapes that you can combine, transform, or modify to create more complex parts.

All primitives are parametric: you specify their size in code, and can later adapt them easily by changing parameters.

Model resolution

All the models are generated below with deflection 0.2 to lower the file size.

box(width, depth, height)

Creates a rectangular box (a cuboid).

local p = box(20, 10, 5)
emit(p)
  • width → size along the X axis
  • depth → size along the Y axis
  • height → size along the Z axis

cylinder(diameter, height)

Creates a vertical cylinder centered in x/y

local c = cylinder(5, 20)
emit(c)
  • diameter → cylinder diameter
  • height → cylinder height

sphere(diameter)

Creates a sphere centered in origin.

local s = sphere(10)
emit(s)
  • diameter → sphere diameter

cone(d1, d2, height)

Creates a conical or frustum-shaped solid.

local co = cone(10, 2, 10)
emit(co)
  • d1 → bottom diameter
  • d2 → top diameter (set to 0 for a true cone)
  • height → cone height

wedge(dx, dy, dz, ltx)

Creates a wedge — essentially a box with slanted top faces.

local w = wedge(20, 10, 10, 5)
emit(w)
  • dx, dy, dz → base box dimensions
  • ltx → shift of left corner

hex_prism(diameter, height)

Creates a regular hexagonal prism (like a bolt head).

local h = hex_prism(5, 2)
emit(h)
  • diameter → distance from flat to flat side (across)
  • height → prism height

Tips for Working with Primitives

  • Start simple: Every complex part begins as a box, cylinder, or combination.
  • Think parametrically: Store dimensions in variables, so you can easily adapt them later.
  • Combine with Booleans: Use difference, union, and intersection to cut holes, join parts, or trim shapes.