Skip to main content

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
MemberContract
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 managerCalls close() on exit and preserves normal exception propagation
sessionThe 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

GroupMethods
Primitivesbox, cylinder, sphere, cone
Importimport_step, import_brep, import_stl
Curves and wirespolyline, circle_profile, arc, interpolate, helix, bspline
Faces and surfacesface, bezier_surface, fit_surface, ruled_surface, filling_surface, gordon_surface
Featuresextrude, revolve, loft, sweep, twisted_sweep, fillet, chamfer, shell
Booleans and stitchingcut, union, intersect, sew, shell_to_solid
Transformstranslate, rotate, mirror, scale
Querydistance, faces, subshapes, free_boundaries
Local constructionworkplane, 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.