Add Curve
add_curveUse this when you need to author a 3D Curve3D into the user's .kcad.ts immediately before the last top-level return. One authoring path, selected by kind:
'nurbs' — insert a
nurbsCurve(controlPoints, opts?)declaration. PasscontrolPointsas a Vec3[] (mm, at least 2 points). Optional NURBS knobs:degree(default 3), rationalweights, explicitknots,closed.'hermite' — insert a
hermiteG2(a, b)declaration: a quintic Hermite curve interpolating two endpoints with matching positions, tangents, and (optional) curvatures — bridges two curves with G2 continuity. Each endpoint is{ point: Vec3, tangent: Vec3, curvature?: Vec3 }in mm; tangent magnitude ~ chord length; curvature defaults to [0,0,0] (G1-only). The returned binding has type Curve3D (peer to Shape / Surface) — consume it viaadd_variable_sweep(spine input),add_surface({ kind: 'boundary' })(boundary curve), or downstream Curve3D-accepting features. Returns the modified code + diagnostics from re-evaluating. Side-effect-free. Each kind fails closed on its own missing required params.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| a | No | kind:'hermite' — start endpoint. | |
| b | No | kind:'hermite' — end endpoint. | |
| code | Yes | The .kcad.ts source code. | |
| kind | Yes | Which curve-construction path to use. | |
| knots | No | kind:'nurbs' — optional explicit knot vector; missing => clamped-uniform inferred. | |
| closed | No | kind:'nurbs' — optional periodic/closed-curve flag. | |
| degree | No | kind:'nurbs' — curve degree; default 3 (cubic). | |
| weights | No | kind:'nurbs' — optional rational weights, one per control point (same length as controlPoints). | |
| binding_name | No | JS const name for the new Curve3D binding (default: _curve_<N>). | |
| controlPoints | No | kind:'nurbs' — control points as Vec3 triples in mm; at least 2 entries. |
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). |