Smith turns Elixir values into precise geometry and printable files. Start with a small script, then extract named functions as the design grows. If CAD is new to you, keep CAD concepts open alongside this guide. The examples use millimeters and run in document order.
Install the native toolkit
Follow OCEx installation to install the supported OCCT 7.9.3 build and set OpenCASCADE_DIR. Install Elixir 1.18 or newer. The native NIF compiles automatically the first time the dependency is compiled; subsequent runs reuse the compiled library.
The OCCT libraries must remain installed after compilation. A successful Mix dependency download alone does not provide the toolkit.
Choose a script or project
For a standalone file:
Mix.install([{:smith, "~> 0.2.0"}])For an existing Mix application, add {:smith, "~> 0.2.0"} to its dependencies and run mix deps.get. Use Mix.install only in standalone scripts or notebook setup, not inside an existing Mix project. There is no Smith application process or supervision tree to configure.
Define a reusable part
defmodule Mount do
alias Smith.Sketch
def build(width \\ 60, depth \\ 40, thickness \\ 5) do
Sketch.rounded_rectangle(width, depth, 2)
|> Sketch.cut(mounting_holes(width))
|> Smith.extrude(thickness)
end
defp mounting_holes(width) do
for x <- [-width / 3, width / 3], do: Sketch.circle(4, at: {x, 0})
end
end
{:ok, part} = Mount.build() |> Smith.evaluate()
{:ok, files} = Smith.export(part, "output", name: "mount", on_bed: true)
IO.puts(files.three_mf)Interactive preview available in HexDocs.
build/3 returns an immutable Smith.Model. Native operations run at evaluation. Reusing a recipe does not mutate the original or share a mutable modeling context.
Use a struct for parameters when a design has many dimensions; pass it to feature functions. Ordinary Enum.map, comprehensions, and pipelines are enough for patterns and assembly construction. Parameter values do not need a separate schema or framework.
Model types
| Value | Meaning |
|---|---|
Smith.Plane | A deferred local coordinate frame |
Smith.Sketch | A connected 2D region with optional holes |
Smith.Model | A deferred edge, face, or solid recipe |
Smith.Result | An evaluated native shape plus geometry revision |
Smith.Assembly | A recipe with named manufactured parts and references |
Smith.Assembly.Result | Evaluated members and their installed compound |
Bare sketches evaluate to faces, which can be inspected with OCEx.area/1. Extrude, revolve, loft, or sweep before printable export. A model recipe may also describe an edge or an empty compound; successful evaluation does not necessarily mean a printable solid.
Check the result
{:ok, width} = Smith.Measure.extent(part, :x)
{:ok, report} = Smith.Inspection.run(%{mount: part}, checks: [
{:measurement, :mount, width, expected: 60, tolerance: 1.0e-6},
{:topology, :mount, :solids, expected: 1}
])
:passed = report.statusInteractive preview available in HexDocs.
Queries return tagged results. Dimensions use millimeters, volumes cubic millimeters, and modeling angles degrees. Meshing angles use radians. Start with verified export defaults, then adjust mesh tolerances when necessary; see Exporting.
Open the Livebook guide to see stages while editing. Native geometry and printable exports also work in a terminal without a browser.
Further examples
For an interactive start, open A plate, step by step. For scripts, continue with functions and pipelines, then workplanes and sketches. The Livebook catalog orders all lessons by topic and complexity. Read inspection and exporting before relying on a part's dimensions or print files.