Native Graph
Graph is a compact ordered batch for the native C ABI. It is distinct from the richer GraphSession used by Model JSON recording.
import cadflow as cad
graph = cad.Graph()
profile = graph.add(
"polyline",
((0, 0, 0), (30, 0, 0), (30, 20, 0), (0, 20, 0)),
True,
)
face = graph.add("face", profile)
body = graph.add("extrude", face, 0, 0, 5)
volume = graph.add("volume", body)
results = graph.execute()
print(float(results[volume]))
Nodes and references
Graph.add(op, *args) -> int appends an immutable Node and returns its zero-based index. An integer argument that represents a shape input refers to an earlier node. Forward references and out-of-range indices are invalid.
Because numeric operation parameters may also be integers, argument interpretation is operation-specific. Follow the exact native operation signature when constructing dynamic batches.
Execution
results = graph.execute(session=None)
When session is omitted, execution creates and closes a temporary NativeSession. Passing an existing session allows the caller to control native lifetime, but graph results remain serialized strings rather than Shape wrappers. Results appear in node order.
Decode each result according to its operation:
- scalar measurements use
float(value)orint(value)as documented; - vectors and bounding boxes are whitespace-separated numeric strings;
- shape-producing nodes return native result identifiers intended primarily for later graph nodes;
- export nodes should be verified through their output paths.
Operation families
The batch surface covers primitives, curves and profiles, surfaces, features, booleans, transforms, topology extraction, measurements, and selected imports/exports. Query Model.capabilities() or consult generated operation pages before accepting an arbitrary operation name from another system.
When to use Graph
Use it when the complete plan is known, reducing boundary crossings matters, and ordered scalar or file results are sufficient. Use Model when Python needs to inspect or branch on live shapes. Use recording and replay when the graph must preserve semantic tags, structured product state, or Model JSON.
Error behavior
Compilation validates supported operations and node references before or during native dispatch. Native failure aborts the batch with NativeError; partial native state is not a portable result. Keep graphs bounded and attach application context to the failed node when generating them dynamically.