Skip to content

Query a CAD model with cadlib

cadlib loads the CAD model a method receives as input and runs geometry queries on it: volume, bounding box, tessellation, and more. Use it in the method's Docker image; for validations, use the CAD validation helpers instead.

Language Package Registry Repository
Python simscale-cadlib PyPI simscale-python-cadlib
Go github.com/SimScaleGmbH/simscale-go-cadlib pkg.go.dev simscale-go-cadlib
Rust simscale-cadlib crates.io simscale-rust-cadlib

Each repository's README is the full guide: install options, CI, Docker and troubleshooting.

Install

Python

Needs CPython 3.12 or newer. The package bundles the native library, so this is the whole setup:

pip install simscale-cadlib

Go

Needs Go 1.21 or newer with cgo enabled. On Windows, cgo needs mingw-w64 gcc, not Visual Studio's compiler.

  1. Install the native library with the install-cadlib.sh (Linux, macOS) or install-cadlib.ps1 (Windows) script from the repository.
  2. Add the module:
go get github.com/SimScaleGmbH/simscale-go-cadlib@v<version>

Rust

Needs Rust 1.71 or newer.

  1. Install the native library with the install-cadlib.sh (Linux, macOS) or install-cadlib.ps1 (Windows) script from the repository.
  2. Add the crate:
cargo add simscale-cadlib@<version>

For Go and Rust, the native library and the binding must come from the same release: if you depend on version 1.2.0, run the script from the v1.2.0 tag. Rerun it whenever you change the version. In Docker, install the library in both the build and the runtime stage.

Supported platforms

OS Architecture Requires
Linux x86_64, aarch64 glibc 2.28 or newer (Debian 10+, Ubuntu 20.04+, RHEL 8+)
macOS Apple silicon macOS 11 or newer
Windows x86_64 Windows 10 or newer; for Go and Rust, the VC++ 2015–2022 redistributable

Alpine and other musl-based images, Intel Macs and Windows on Arm are not supported.

Run a first query

Pass the CAD entry of the method's dataMap to load, then query the model. Loading is expensive, so load once and reuse the instance for every query.

Python

from cadlib import Cad, VolumeParameters

cad = Cad.load(request.data_map.cad)
result = await cad.volume(VolumeParameters(entity_ids=["B1_TE5"]))

Queries are async.

Go

cad, err := cadlib.Load(request.DataMap.Cad)
if err != nil {
    return err
}
defer cad.Close()

result, err := cad.Volume(&cadlib.VolumeParameters{EntityIDs: []string{"B1_TE5"}})

Queries block. Don't query one instance from several goroutines at once.

Rust

use cadlib::{Cad, VolumeParameters};

let cad = Cad::load(&request.data_map.cad)?;
let params = VolumeParameters { entity_ids: vec!["B1_TE5".to_string()] };
let result = cad.volume(Some(&params))?;

Queries block; from async code, run them with spawn_blocking. Don't query one instance from several threads at once.

Errors are either expected, with a stable error_code to match on, or unexpected: a bug or an environment problem. ERRORS.md in each repository lists every error code.

API reference

pkg.go.dev (Go), docs.rs (Rust) and the repository README (Python).