Model
class Model(session: NativeSession | None = None)
Model is the recommended entry point for interactive native geometry. It owns a NativeSession by default and wraps returned native handles as Shape values.
Lifecycle
import cadflow as cad
with cad.Model() as model:
body = model.box(40.0, 25.0, 6.0)
result = body.describe(detail="summary")
# body must not be queried here
| Member | Contract |
|---|---|
Model() | Create and own a new NativeSession |
Model(session) | Borrow an existing session; the caller owns its final close |
close() | Close only a session created by this model |
| context manager | Calls close() on exit and preserves normal exception propagation |
session | The active low-level session; prefer model methods unless implementing an adapter |
All shape-to-shape calls check session identity. A shape from another model raises ValueError before native dispatch where the frontend can detect it.
Construction groups
| Group | Methods |
|---|---|
| Primitives | box, cylinder, sphere, cone |
| Import | import_step, import_brep, import_stl |
| Curves and wires | polyline, circle_profile, arc, interpolate, helix, bspline |
| Faces and surfaces | face, bezier_surface, fit_surface, ruled_surface, filling_surface, gordon_surface |
| Features | extrude, revolve, loft, sweep, twisted_sweep, fillet, chamfer, shell |
| Booleans and stitching | cut, union, intersect, sew, shell_to_solid |
| Transforms | translate, rotate, mirror, scale |
| Query | distance, faces, subshapes, free_boundaries |
| Local construction | workplane, sketch |
The creation, features, and topology/exchange pages document parameter interpretation and workflow boundaries. The generated Model page is the exact member inventory.
Dynamic dispatch
capabilities() describes recognized operations and feature groups without exposing private handles. Use it when another system selects operations at runtime.
caps = model.capabilities()
report = model.preflight("box", 40.0, 25.0, 6.0)
if report.ok:
created = model.apply("box", 40.0, 25.0, 6.0)
body = created.value
preflight() normalizes common call mistakes and returns an OperationReport; it does not build geometry. apply() runs preflight and invokes the named public model operation. For statically known code, direct methods are simpler and preserve better type checking.
Workplanes and sketches
model.workplane(...) returns a model-attached local frame. Its curve helpers convert local coordinates to world coordinates before creating shapes. model.sketch(...) creates a declarative sketch on an optional Workplane.
with model.workplane(origin=(0, 0, 10), normal=(0, 1, 0)) as plane:
profile = plane.circle_profile(4.0)
face = model.face(profile)
pin = plane.extrude(face, (0, 0, 12.0))
Failure and side effects
Primitive dimensions, tolerances, vectors, and paths are validated by the corresponding native or domain call. Import and export methods perform file I/O. Geometry operations return new shapes; they do not mutate input handles. Close the model in all paths, preferably with with.
See errors and diagnostics for dynamic operation recovery and API conventions for ownership and units.