Skip to content

OCL language

OCL (openIE CAD Language) describes designs as code. The evaluator turns OCL into geometry and populates the UDD; the viewer renders the result. Agents call it through eval_ocl (parse + evaluate) and parse_ocl (parse only) — see MCP tools. For a gentle introduction, start with OCL basics.

The interactive form of an OCL program is a sequence of let bindings. Each binds a name to a value:

let base = box(40mm, 20mm, 10mm)
let lid = box(40mm, 20mm, 2mm)

Lengths carry an explicit unit (mm). OCL enforces dimensional analysis — mixing incompatible dimensions is an error, not a silent bug.

let w = 40mm
let plate = box(w, 20mm, 2mm)
PrimitiveArguments
box(width, height, depth)three lengths
cylinder(radius, height)two lengths

|> feeds a value into a transform, applied left to right:

let post = cylinder(1.6mm, 8mm) |> translate(10mm, 5mm, 0mm)

translate(x, y, z) moves a solid by the given offsets.

Beyond interactive bindings, OCL can describe a complete product — enclosure, schematic, circuit, and bill of materials — in a single source. The evaluator populates the UDD from it, so every downstream view (viewer, agent, fab) reads from one place:

product "USB Temperature Logger" {
body Case {
let shell = box(46mm, 24mm, 16mm)
}
schematic Main {
place U1 at (8mm, 10mm) -- MCU
place U2 at (24mm, 10mm) -- sensor
wire(U1.SDA, U2.SDA)
wire(U1.SCL, U2.SCL)
}
circuit Power {
V1(VCC, GND) = 3.3V
R1(VCC, LED) = 330ohm
}
bom {
entry U1 { mpn = "ESP32-C3-MINI-1", unit_price = 1.70 }
entry U2 { mpn = "SHT40-AD1B-R2", unit_price = 2.10 }
}
}

The mechanical body, the schematic, the circuit, and the bom share identifiers — change a component once and every section follows.

OCL ships with a lexer, parser, evaluator, and an LSP server (with a VS Code extension) in the cad-ocl and cad-ocl-lsp crates — see the crate map.