Quickstart
This walkthrough creates a mounting plate with a through bore, checks the resulting solid, and exports both an engineering STEP file and a browser-ready GLB preview.
Build the part
Create mounting_plate.py:
import json
from pathlib import Path
import cadflow as cad
output = Path("output")
output.mkdir(exist_ok=True)
with cad.Model() as model:
plate = model.box(80, 50, 8)
bore = model.cylinder(radius=6, height=12)
bore = model.translate(bore, 20, 25, -2)
part = model.cut(plate, bore)
report = part.validate()
if not report.ok:
raise RuntimeError(report.to_dict())
print(json.dumps(part.describe(), indent=2))
part.export_step(str(output / "mounting_plate.step"))
part.export_stl(str(output / "mounting_plate.stl"))
part.export_preview_glb(str(output / "mounting_plate.glb"))
Run it inside the environment where CadFlow is installed:
python mounting_plate.py
ls -lh output/
Understand the model lifetime
cad.Model() owns a native C++ session. Every Shape returned by that model is a lightweight handle into the session:
Model context
└─ native Session
├─ plate handle
├─ bore handle
└─ final part handle
Shapes from different models cannot be combined, and handles become invalid after the model closes. Keep construction, measurement, and export inside the with cad.Model() block.
Read structured geometry evidence
Shape.describe() returns JSON-safe values instead of formatted console text. A summary includes fields such as:
{
"kind": "solid",
"volume": 18904.42,
"bbox": [0.0, 0.0, 0.0, 80.0, 50.0, 8.0],
"topology": {
"solids": 1,
"faces": 7
}
}
Exact counts and floating-point values depend on the resulting OCCT topology. Use report fields programmatically; do not parse display strings.
Validate before delivery
Shape.validate() checks the shape and returns an OperationReport. For delivery code, combine it with workflow-specific invariants:
report = part.validate()
if not report.ok:
raise RuntimeError(report.to_dict())
if part.topology.get("solids") != 1:
raise RuntimeError(f"expected one solid: {part.topology}")
if part.volume <= 0:
raise RuntimeError("part has no positive volume")
This separates kernel validity from your engineering expectations.
Choose an output
| Output | Method | Typical consumer |
|---|---|---|
| STEP | shape.export_step(path) | CAD systems and downstream manufacturing workflows |
| STL | shape.export_stl(path, binary=True) | Mesh-based fabrication and inspection tools |
| GLB | shape.export_preview_glb(path) | Browsers, web viewers, and agent run records |
| Mesh arrays | shape.mesh(deflection=0.1) | Custom renderers and numeric processing |
Next steps
- Add profiles, features, and transforms in Modeling basics.
- Build constrained 2D geometry with Sketches and workplanes.
- Harden an artifact pipeline with Inspect, validate, and export.