Inspect, validate, and export
A successful kernel call is not enough to prove that a CAD artifact is correct. A dependable workflow records geometric evidence, checks domain invariants, writes the required formats, and verifies the files that were created.
Inspect a shape
Core Shape properties are calculated in the native session:
evidence = {
"kind": part.kind,
"volume_mm3": part.volume,
"area_mm2": part.area,
"center_of_mass_mm": part.center_of_mass,
"bbox_mm": part.bbox,
"topology": part.topology,
}
Use part.describe() for a JSON-safe aggregate or part.describe(detail="mesh") when a mesh is explicitly needed. Avoid the mesh detail mode for routine checks because it produces substantially more data.
Validate geometry and intent
Shape.validate() performs inexpensive backend-neutral checks and returns an OperationReport:
report = part.validate()
if not report.ok:
raise RuntimeError(report.to_dict())
Then check the expectations specific to the part:
expected_bbox = (0, 0, 0, 80, 50, 8)
if part.topology.get("solids") != 1:
raise RuntimeError("delivery must contain exactly one solid")
if part.volume <= 0:
raise RuntimeError("delivery solid must have positive volume")
for actual, expected in zip(part.bbox, expected_bbox):
if abs(actual - expected) > 0.1:
raise RuntimeError(f"unexpected bounds: {part.bbox}")
Kernel validity and design intent are separate claims; check both.
Preflight agent-authored operations
Model.preflight() catches common mistakes before invoking geometry:
check = model.preflight("fillet", part, 2.0, edges=[0, 4, 99])
if not check.ok:
for diagnostic in check.diagnostics:
print(diagnostic.code, diagnostic.message, diagnostic.hint)
Current checks include session mismatches, invalid edge indices, and non-positive shell thickness. Model.apply() combines preflight, execution, and structured failure reporting for agent loops.
Export artifacts
from pathlib import Path
output = Path("artifacts/mounting_plate")
output.mkdir(parents=True, exist_ok=True)
part.export_step(str(output / "mounting_plate.step"))
part.export_stl(str(output / "mounting_plate.stl"), binary=True)
part.export_preview_glb(str(output / "mounting_plate.glb"), deflection=0.25)
Mesh deflection controls preview tessellation, not the underlying exact BREP. A smaller value usually produces more triangles.
Verify delivery files
At minimum, confirm that each required file exists and is non-empty:
for path in output.iterdir():
if path.stat().st_size == 0:
raise RuntimeError(f"empty artifact: {path}")
For higher-assurance delivery:
- Re-import the STEP file through
Model.import_step(). - Compare volume, bounds, topology, or BREP inspection results with the source shape.
- Render orthographic views and inspect them visually.
- Store validation evidence in a JSON report beside the artifact.
- Record hashes when artifacts move between systems.
The public cadflow.inspection and cadflow.inspect.brep surfaces provide detailed STEP/BREP inspection and comparison workflows. They are useful when exact delivery parity matters more than a simple round trip.
Recommended artifact layout
artifacts/mounting_plate/
├── mounting_plate.step
├── mounting_plate.stl
├── mounting_plate.glb
├── mounting_plate.png
└── report.json
Keep the model script and report in version control when reproducibility matters. Large generated geometry files can use release assets or external artifact storage.