Add Pattern Feature
add_pattern_featureUse this when you need to repeat a feature in a pattern. Insert a Shape.patternLinear / .patternCircular / .patternGrid call into a kernelCAD script before the last top-level return. Pass structured args (kind + the matching spec object). Returns the modified code plus diagnostics from re-evaluating. Side-effect-free. The pattern feature is a single editable unit; pattern-instance face refs resolve via <sourceId>_pattern_<i> on the pattern feature's lineage. Geometric note: pattern is implemented as cumulative boolean union of transformed source copies — additive features (boxes, ribs, fins, spokes) pattern cleanly; patterning a subtractive feature (hole, cutout) only preserves the per-instance void when adjacent bodies are disjoint.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | The .kcad.ts source code. | |
| grid | No | Required when kind=grid. | |
| kind | Yes | ||
| linear | No | Required when kind=linear. | |
| target | Yes | Variable name of the Shape to pattern (inserted verbatim as the LHS receiver). | |
| circular | No | Required when kind=circular. | |
| assign_to | No | Optional const-binding name; emits `const <assign_to> = <target>.patternX(...);`. Omit for statement form. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ok | Yes | Whether the edit applied and re-evaluated cleanly. | |
| error | No | Failure message (present when ok is false). | |
| new_code | No | Modified .kcad.ts source (present on success). Caller persists it. | |
| diagnostics | No | Diagnostics from re-evaluating the modified source. | |
| binding_name | No | JS const name bound to the new construct (when one was created). |