Skip to content

OCL basics

OCL is openIE CAD’s design language. It lets you describe geometry as precise, repeatable code instead of a conversation. The evaluator turns OCL into real B-Rep solids in your project, which the app renders directly. Your agent can run a snippet for you with the eval_ocl tool, or you can write it by hand.

In this lesson you’ll learn the four ideas that make up everything you’ll write — bindings, units, primitives, and the pipe — then put them together in a small assembly.

An OCL program is a sequence of let bindings. Each binds a name to a value, and most values are solids:

let base = box(40mm, 20mm, 8mm)

Run that and you get one body named base. Later lines can refer to it by name, which is how you build up a design step by step.

Geometry in OCL is always dimensioned. Every length carries a unit suffix — you write 40mm, never bare 40. OCL enforces dimensional analysis, so a length and an area can never be silently mixed up. This is what keeps your model unambiguous: there’s no hidden “default unit” to guess at.

let thickness = 2mm
let plate = box(40mm, 20mm, thickness)

You’ll build most parts from two solids:

let b = box(40mm, 20mm, 8mm) -- width, depth, height
let c = cylinder(3mm, 12mm) -- radius, height

box(...) takes width, depth, and height. cylinder(...) takes the radius first, then the height. Both always use mm.

A freshly created solid sits at the origin. To move it, use the pipe operator |>, which feeds a value into a transform — read it left to right:

let post = cylinder(1.6mm, 9mm) |> translate(18mm, 0mm, 0mm)

That creates a cylinder and moves it 18 mm along x. translate(x, y, z) takes three lengths, one per axis.

Let’s combine all four ideas into a small enclosure: a shell, a PCB sitting inside it, and two standoffs to hold the board.

let shell = box(46mm, 24mm, 16mm)
let pcb = box(40mm, 18mm, 1.6mm) |> translate(0mm, 0mm, 4mm)
let standoff1 = cylinder(1.6mm, 4mm) |> translate(18mm, 0mm, 0mm)
let standoff2 = cylinder(1.6mm, 4mm) |> translate(-18mm, 0mm, 0mm)

Reading it line by line: shell is the outer box; pcb is a thin board lifted 4 mm off the floor; standoff1 and standoff2 are two posts moved to either side to support it. Evaluate the snippet and the app shows the shell, the board, and the standoffs together.

You can now describe geometry as code. Next you’ll switch from mechanical to electrical and lay out a board: Next → Your first board.