Add Surface
add_surfaceUse this when you need an organic, freeform, or swept shape — a body shell, panel, fairing, ergonomic curve, lens, or sculpted form — authored as a NURBS Surface into the user's .kcad.ts, OR when you need to finish surfaces into a watertight solid or taper faces for moldability. One authoring/finishing 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. Weights are honored: supply rational weights to build exact circles/cylinders/spheres/conics (the surface becomes rational); omit weights for a non-rational surface.
'patchFamily' — insert a nurbsPatchFamily(...) solid built from degree-5+ shared-knot NURBS caps. Pass { controls, degree, split_direction, extrusion, split_knot? }. The selected split knot must have multiplicity m <= split-direction degree - 4 (C4 or better). For finite rectangular, non-rational, non-periodic inputs with C1-or-better split-direction knots and C4-or-better tangential knots, outward-rounded active derivative-control intervals must keep one Jacobian component strictly away from zero on every pair of nonzero U/V knot spans of both actual caps; rotated control nets can qualify. The lowerer independently enumerates both internal cap split seams and requires finite D0–D4 conformance samples plus a valid nonempty one-solid B-rep. Samples are a fail-closed cross-check, not the continuous proof. Any inconclusive cell or other unsupported input remains sampled-only or uncertified. Cap-to-side closure seams and whole-solid G4 are outside this certificate scope.
'planeBlend' — insert planeBlendSurface(railA, railB, { normalA, normalB, handleLengthMm? }) for two corresponding, equally oriented, straight parallel rails on planar supports. This is a separate G2 blend construction, not an OCCT fillet. Pass rail_a_binding / rail_b_binding (declared Curve3D variables) and unit support normals. Sew the returned patch with both support surfaces; the measured achieved class belongs to those joined seams.
'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).
'trim' — insert a
<surface>.trimTo(<by>)or<surface>.split(<by>)call. Passsurface_binding(the Surface variable name),by_binding(the cutter Surface variable name; Shape/Curve3D cutters are deferred to a later slice), andop: 'trim'(keep the largest imprinted piece) orop: 'split'(return both halves as a[Surface, Surface]tuple).'sew' — insert a
sew([s0, s1, ...], opts?)call to stitch N surfaces. Passsurface_bindings(array of Surface variable names). Optionalcontinuity: 'G0'|'G1'|'G2'|'G3'|'G4'asks the lowerer to report sampled shared-seam results. G3/G4 always produce a warning, even when all finite samples meet their thresholds; the results are explicitly sampled-only and uncertified, with no exact or seam-wide proof. ThenurbsPatchFamilyanalytic certificate is limited to its two internal cap split seams and the documented input class; other inputs remain uncertified. Lower-grade requests warn when their measured class is below the request.tolerancedefaults to 1e-6 mm;require_closederrors if the result is not watertight.'draft' — insert a
<shape>.draft(angleDeg, { face, neutralPlane?, pullDir? })call to taper the selected face(s) for mold release. Passshape_binding,angle_deg(0–90), andface(canonical name, label, or FaceQuery descriptor). Lowering emits feature.draft.failed on invalid geometry. 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.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"kind": "<kind>",
"code": "<code>"
},
"name": "add_surface"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| op | No | kind:'trim' — 'trim' discards the smaller half (calls .trimTo()); 'split' retains both halves (calls .split()). | |
| code | Yes | Current .kcad.ts source. | |
| face | No | kind:'draft' — face selector for the face(s) to taper. Accepts a canonical name (top/bottom/front/back/left/right), a user label declared via faceLabels, or a FaceQuery descriptor string. | |
| kind | Yes | Which surface-construction or surface-finishing path to use: 'nurbs' | 'patchFamily' | 'planeBlend' | 'boundary' | 'trim' | 'sew' | 'draft'. | |
| knots | No | kind:'nurbs' or 'patchFamily' — optional explicit knot vectors; missing => clamped uniform inferred. patchFamily split_knot must select an interior knot with multiplicity <= split-direction degree - 4. | |
| degree | No | kind:'nurbs' or 'patchFamily' — degrees in U and V; patchFamily requires split-direction degree >= 5 and enough controls for an interior knot with multiplicity <= degree - 4. | |
| weights | No | kind:'nurbs' or 'patchFamily' — optional positive rational weights, same grid shape as controls. Rational weights are outside the restricted patchFamily analytic certificate class. | |
| controls | No | kind:'nurbs' or 'patchFamily' — control-point grid (controls[u][v] = [x, y, z], mm). patchFamily uses degree-5+ caps and an interior split knot with multiplicity <= split-direction degree - 4. | |
| normal_a | No | kind:'planeBlend' — unit normal of the first planar support face. | |
| normal_b | No | kind:'planeBlend' — unit normal of the second planar support face. | |
| periodic | No | kind:'nurbs' — optional periodic flags per parametric direction. | |
| pull_dir | No | kind:'draft' — demoulding direction as [x, y, z]. Defaults to the face normal at lower time. | |
| sampling | No | kind:'boundary' — points sampled along each boundary (default 15). | |
| angle_deg | No | kind:'draft' — draft angle in degrees [0, 90]. The face is tapered outward by this angle relative to the pull direction. | |
| extrusion | No | kind:'patchFamily' — finite non-zero translation [x, y, z] in mm from the first NURBS cap to the opposite cap. | |
| tolerance | No | kind:'sew' — edge-merging tolerance in mm (default 1e-6). Edges within this distance are merged. | |
| by_binding | No | kind:'trim' — JS variable name of the cutter Surface (must be declared in source). Shape/Curve3D cutters are deferred. | |
| continuity | No | kind:'boundary' — C0 only; C1/C2 fail because no neighboring support surfaces are supplied. kind:'sew' — minimum sampled continuity for every topology-enumerated shared seam ('G0' | 'G1' | 'G2' | 'G3' | 'G4'); G3/G4 use common-UV NURBS samples and are explicitly uncertified, not exact or seam-wide proofs. | |
| split_knot | No | kind:'patchFamily' — optional knot value to split at; defaults to the first interior knot whose multiplicity gives C4 or better. | |
| binding_name | No | JS const name for the new binding (kind:'nurbs' default surface_<N>; kind:'patchFamily' default patch_family_<N>; kind:'planeBlend' default plane_blend_<N>; kind:'boundary' default _surface_<N>; kind:'trim' default _trimmed_<N>; kind:'sew' default _sewn_<N>; kind:'draft' default _drafted_<N>). | |
| neutral_plane | No | kind:'draft' — parting-line face (the plane where drafted faces remain fixed). Defaults to `face` if omitted. | |
| shape_binding | No | kind:'draft' — JS variable name of the Shape to taper (must be declared in source). | |
| curve_bindings | No | kind:'boundary' — tuple of 4 existing Curve3D variable names (bottom, right, top, left) declared earlier in the source. | |
| face_tolerance | No | kind:'patchFamily' — positive OCCT face-construction tolerance in mm (default 1e-6). | |
| rail_a_binding | No | kind:'planeBlend' — existing Curve3D variable name for the first straight support rail. | |
| rail_b_binding | No | kind:'planeBlend' — existing Curve3D variable name for the second corresponding, parallel support rail. | |
| require_closed | No | kind:'sew' — when true the lowerer emits feature.surface-sew.open-shell if the stitched result is not a watertight solid. | |
| split_direction | No | kind:'patchFamily' — parameter direction for the shared interior knot with multiplicity <= degree - 4 and measured target seam. | |
| surface_binding | No | kind:'trim' — JS variable name of the Surface to trim/split (must be declared in source). | |
| handle_length_mm | No | kind:'planeBlend' — positive quintic control-handle length in mm; default is one tenth of the rail gap. | |
| surface_bindings | No | kind:'sew' — JS variable names of the surfaces to stitch into a solid (each must be declared in 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 |
|---|---|---|---|
No arguments | |||