Add Surface
add_surfaceUse this when you need to author a NURBS Surface into the user's .kcad.ts. One authoring path, selected by kind:
'nurbs' — insert a nurbsSurface(...) / surfaceFromCurves(...) call. Pass either { controls, degree, weights?, knots?, periodic? } for direct construction, OR { section_sketch_ids } for skinning. Slice-1 limitation: weights are accepted but currently ignored (TColStd_Array2OfReal not exposed in WASM bindings); surfaces are non-rational.
'boundary' — insert a surfaceFromBoundary([c1,c2,c3,c4], opts?) call: one NURBS face through 4 boundary Curve3D refs (bottom, right, top, left in loop order; adjacent endpoints must coincide within 1e-6 mm) via OCCT BRepOffsetAPI_MakeFilling. The returned Surface produces no Shape until you chain .thicken(t) or .toShape() (do that via add_feature on the binding name). Returns the modified code + diagnostics. Each kind fails closed on its own missing required params.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | Current .kcad.ts source. | |
| kind | Yes | Which surface-construction path to use. | |
| knots | No | kind:'nurbs' — optional explicit knot vectors; missing => clamped uniform inferred. | |
| degree | No | kind:'nurbs' — degrees in U and V; each in [1, nU-1] / [1, nV-1]. | |
| weights | No | kind:'nurbs' — optional rational weights, same grid shape as controls. Ignored in slice-1. | |
| controls | No | kind:'nurbs' — control-point grid for direct construction (controls[u][v] = [x, y, z], mm). | |
| periodic | No | kind:'nurbs' — optional periodic flags per parametric direction. | |
| sampling | No | kind:'boundary' — OCCT NbPtsOnCur sampling parameter (default 15). | |
| continuity | No | kind:'boundary' — continuity grade applied to every edge ('C0' | 'C1' | 'C2'), or an array of 4 grades (one per edge, bottom/right/top/left order). Default 'C0'. | |
| binding_name | No | JS const name for the new Surface binding (kind:'nurbs' default surface_<N>; kind:'boundary' default _surface_<N>). | |
| curve_bindings | No | kind:'boundary' — tuple of 4 existing Curve3D variable names (bottom, right, top, left) declared earlier in the source. | |
| section_sketch_ids | No | kind:'nurbs' — existing sketch FeatureIds (2 or more) to skin a surface through, in order. |
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). |