Skip to main content

Sketch API

CadFlow provides a modern SketchDocument frontend and a compatibility Sketch data model. Both represent declarative 2D geometry on a plane; methods and helper functions return updated values rather than mutating prior state.

Document workflow

with cad.Model() as model:
sketch = model.sketch("plate")
sketch = sketch.add_point("a", 0, 0).add_point("b", 40, 0)
sketch = sketch.add_point("c", 40, 20).add_point("d", 0, 20)
sketch = (
sketch.add_line("ab", "a", "b")
.add_line("bc", "b", "c")
.add_line("cd", "c", "d")
.add_line("da", "d", "a")
.constrain_horizontal("ab")
.constrain_vertical("bc")
.constrain_fix("a")
)
solve = sketch.inspect(strict=False)
face = sketch.to_native_face(model, strict=False)

Entity names are stable references inside the sketch. Choose descriptive unique IDs because diagnostics and constraint references report them.

Entity types

The public surface covers points, lines, circles, arcs, and B-splines. SketchRef identifies an entity or point result. Compatibility helpers use names such as add_line_rsketch and explicitly return the replacement sketch.

Constraints

FamilyPublic relationships
Incidencecoincident, connect, point-on, midpoint
Orientationhorizontal, vertical, parallel, perpendicular, collinear
Curvestangent, concentric, equal radius
Symmetry and equalitysymmetric, equal length
Dimensionsdistance, X/Y distance, length, angle, radius, diameter
Groundingfix

Avoid redundant constraints. Fix only enough geometry to remove rigid-body freedom, then let dimensional and geometric relations determine the remaining degrees of freedom.

Solver and inspection

SketchSolverOptions controls tolerance and iteration limits. Solver backends can be registered, selected globally, or selected through the sketch_solver_backend(...) context manager. SketchSolveResult reports status, degrees of freedom, diagnostics, and solved values.

Use strict=False while building or repairing a sketch. Use strict=True or require_fully_constrained=True when underconstrained or inconsistent state must stop artifact generation.

Lowering to geometry

make_wire_from_sketch_rwire and make_face_from_sketch_rface solve and lower a selected profile. SketchDocument.to_native_face(model, strict=...) produces a native, model-owned face. Profile selectors may be an index or stable name, and inner profiles can define holes where supported.

The sketch is source state; the face or wire is derived topology. After changing constraints or entities, lower a new shape instead of assuming the old shape updates.

See all 47 Sketch symbols.