Add Text
add_textUse this when you need to author text into a kernelCAD script before the last top-level return. One authoring path, selected by mode:
'sketch' — insert a sketch.text(...) call. The emitted sketch is chainable: pair with subsequent .extrude(...) / cut(...) edits to land an engraved or raised text feature.
'emboss' — insert a
<shape>.embossText({...})chained call onto an existing Shapetarget. Use for engraved brand text on faces (Ray-Ban temple, CE mark, model number).depth > 0raises text out of the face;depth < 0engraves text into the face. Lowers via replicad drawText → sketchOnFace → extrude → fuse|cut. Default font is the runtime-bundled Liberation Sans. Side-effect-free; returns the modified code plus diagnostics from re-evaluating. Each mode fails closed on its own missing required params.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | The .kcad.ts source code. | |
| face | No | mode:'emboss' — target face — canonical name ('top'/'bottom'/'left'/'right'/'front'/'back') or label. | |
| font | No | mode:'sketch' — optional logical font name or .ttf file path; defaults to bundled Liberation Sans. | |
| mode | Yes | Which text-authoring path to use. | |
| size | No | mode:'sketch'|'emboss' — glyph cap height in mm (positive finite). | |
| align | No | mode:'sketch' — horizontal alignment relative to position (default left); mode:'emboss' — relative to the UV anchor (default center). | |
| depth | No | mode:'emboss' — signed extrusion depth in mm: positive emboss out, negative engrave in. Must be non-zero. | |
| bindAs | No | mode:'sketch' — emits `const <bindAs> = sketch.text(...)`; mode:'emboss' — emits `const <bindAs> = <target>.embossText(...);`. | |
| target | No | mode:'emboss' — variable name of the Shape to chain onto (inserted verbatim). | |
| anchorU | No | mode:'emboss' — U anchor in [0, 1] face-local (0=umin, 0.5=centre, 1=umax). Default 0.5. | |
| anchorV | No | mode:'emboss' — V anchor in [0, 1] face-local. Default 0.5. | |
| content | No | mode:'sketch' — text content (UTF-8, non-empty, non-whitespace). | |
| position | No | mode:'sketch' — [x, y] anchor in mm. Default [0, 0]. | |
| rotation | No | mode:'sketch' — CCW rotation in degrees around position (default 0); mode:'emboss' — CCW rotation in the face tangent plane (default 0). | |
| scaleMode | No | mode:'emboss' — Drawing.sketchOnFace scaling mode. Default original. | |
| fontFamily | No | mode:'emboss' — optional logical font name or .ttf file path; defaults to bundled Liberation Sans. | |
| textContent | No | mode:'emboss' — text content (UTF-8, non-empty, non-whitespace). |
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). |