Public command

pcb-svg

Generate configured KiCad PCB SVG design views and optional layer SVG artifacts from an A0 PCB SVG config.

Usage

kicad-cruncher pcb-svg board.kicad_pcb
kicad-cruncher pcb-svg project.kicad_pro --views assembly-top
kicad-cruncher pcb-svg board.kicad_pcb --config board.pcb.svg.config -o output/pcb-svg
kicad-cruncher pcb-svg board.kicad_pcb --layers F.Cu,Edge.Cuts --views layers
kicad-cruncher pcb-svg board.kicad_pcb --workers 8

Arguments

file accepts .kicad_pcb or .kicad_pro. When omitted, the command attempts auto-detection when exactly one KiCad project or PCB file exists in the current directory. --config selects a kicad_cruncher.pcb_svg.config.a0 JSON/JSONC config file. Without it, kcr reads <stem>.pcb.svg.config beside the input, where the stem is the .kicad_pro's and a board given alone uses its own stem, which KiCad shares with its project; a folder pcb.svg.config is the fallback. When neither exists, kcr writes <stem>.pcb.svg.config with that board's generated components (owner, 2026-11-25). --doc selects the board file for project inputs. --views filters configured views and layer outputs. --layers filters layer-output tokens when layer outputs are enabled. -o selects the output directory directly. --cache-dir and --no-cache, which are exclusive, control the persistent cache. --workers N sets the Geometer worker processes for model HLR projections, 1 to 64, default 4. Workers start only for projections missing from the cache. The output does not depend on N.

Reference

kcr follows Altium Cruncher generally, the most developed of kcr, Altium Cruncher and PCB Engine (owner, 2026-11-24). Aligning designators and config with PCB Engine is later work. kcr's config schema and command options are its own public contract, shared with neither tool, since each ships public releases (owner, 2026-11-24); a change updates the TypeSpec and these docs. The 3D illustration is a virtual layer of this command and toon is one of its built-in configs, so any view can show illustrations without the Toon look (owner, 2026-11-24). Python and Rust change together, and each is checked against KiCad and Altium Cruncher references, never against the other.

Config and canvas

resources/pcb.svg.default.jsonc is the one commented default config. Both languages read their defaults from it, and a config kcr writes is that file with its "components": {} line replaced by the generated part rules, written with LF line ends on every platform. An authored config must carry the schema id and overlays the defaults: objects merge key by key, other values replace, and authored views replace the default views, each inheriting the global settings, never another view's. A section it leaves out, even global or layer_outputs, takes the defaults, and the merged config is what the contract validates.

global.canvas gives each board one canvas, shared by every view and layer output. bounds: "board_outline", the default, fits the Edge.Cuts outline (the board's and its footprints' shapes) as BOARD_OUTLINE draws it: each shape's true extent, an arc's and a curve's exact one, grown by half the global styles.board_outline.line_width_mm, or by half its own stroke when that is unset. A view's own outline style does not change it, and a view that hides or leaves out the outline is still framed by it. bounds: "all_geometry", or a board with no outline, fits everything drawn. Either grows by margin_mm (1 mm) on every side. A view that draws an illustration layer grows its frame to the drawn copies. toon frames its views itself.

Output

When -o is omitted, artifacts are written under ./output/pcb-svg/. The command writes one <board>__views.json manifest and configured view SVGs under views/ by default. Standalone per-layer SVGs under layers/ are optional and are enabled by setting layer_outputs.enabled to true or by selecting layers with --views. Each view is composed in layer-token order from kicad-monkey enriched physical SVG groups plus explicit virtual layers: each physical layer's items in KiCad's plot order (tracks, zones, vias, other items, pads), then the next token, as in Rust and Altium Cruncher. Python used to sort every listed layer's items together by kind. Physical SVG geometry uses Monkey's Python renderer on every platform; inherited native-selector flags do not change this. The root SVG records data-compositor-schema="kicad_cruncher.pcb_svg.compositor.a0" and data-layer-tokens.

Artifact publication is transactional: failed rendering leaves a new destination absent and preserves an existing destination exactly. A missing project-adjacent <stem>.pcb.svg.config is intentionally authored before rendering and remains as configuration input even when artifact rendering fails. A config kcr writes, beside the board or at a missing --config path (from the first board when there are several; for a project, the board --doc selects), holds the assembly part rules' entries in components; an existing config is used as written and never regenerated.

Every id in an SVG is unique. A view namespaces each layer's ids, references included, so a footprint drawn on two layers or through its holes keeps unique ids. An element that still repeats an id, as on a board that repeats a source UUID, takes -2, -3, ... in document order, skipping a suffix another id already uses, and the board warns once for all its views and layer outputs. The id count in that warning is per render in Rust and per view in Python.

Virtual Layers

BOARD_OUTLINE and BOARD_CUTOUTS are synthesized from board-level Edge.Cuts geometry. Closed gr_line/gr_arc loops, gr_rect, gr_circle, and gr_poly regions are sampled as closed regions; the largest closed region is treated as the board outline, and smaller closed regions inside it become cutouts. Arc, curve, and circle smoothness for derived board regions is controlled by styles.board_outline.max_arc_segment_mm, max_curve_segment_mm, max_circle_segment_mm, and their segment caps; smaller segment lengths produce smoother but larger SVG paths. Cutouts carry data-layer-key="BOARD_CUTOUTS", data-feature="board-cutout", source-kind/source-UUID metadata, and the default hatch pattern board-cutout-hatch.

DRILLS and SLOTS clone the existing kicad-monkey enriched pad-hole and via-hole groups, preserving canonical data-hole-kind, data-hole-plating, owner, dimensions, component, pad, net, and layer metadata. PIN1_TOP and PIN1_BOTTOM synthesize marker circles from footprint and pad model coordinates. Pad selection order is component override, pad 1, pad A1, grid-style fallback, then first pad. Global or per-view pin1 config can exclude single-pin footprints plus exact designators, numeric ranges such as U5-U15, and prefixes such as U or U*; generated defaults exclude single-pin parts plus R and C. Marker diameter can be a fixed value or a ratio of the selected pad size.

BOARD_SUBSTRATE, SOLDERMASK_FILM_TOP/SOLDERMASK_FILM_BOTTOM and ILLUSTRATION_TOP/ILLUSTRATION_BOTTOM work in any view and as virtual layer outputs, with that view's styles. The substrate is the board domain less its bores. A film covers what is drawn before it and is open where the side's mask layer is. soldermask_film.color "auto" is the board's saved mask colour for the view's side, and silkscreen "contrast" follows it, in every view. An illustration layer draws each footprint's embedded STEP models with Geometer's shaded illustration, the illustration style (outline and detail widths, opacity) and the two board masks described for toon; its Geometer work shares the command's workers and the geometer-illustration cache, and a view that draws one grows its frame to the drawn copies. toon is this pipeline with its built-in config.

ASSEMBLY_DESIGNATORS_TOP and ASSEMBLY_DESIGNATORS_BOTTOM draw each component's reference, fitted inside the part by a rotated-box search on the part's turn and on +90°, preferring the horizontal on a tie, so a 45° part gets a 45° label; toon uses the same path. A footprint whose Reference is empty gets no label and no warning. A label takes the projection its view's HLR uses for the component: components.<designator>.projection, else the view's assembly_hlr_mode (detail when unset; outline in the default assembly views), as Rust and Altium Cruncher; a standalone ASSEMBLY_DESIGNATORS_* layer output uses the component's projection, else assembly.default_projection, as the standalone HLR output does (see HLR). A component projected pad_bounds, pad_shape or none is fitted to its pads: their real shapes on the side's outer copper, electrical pads first, wrapped in one convex outline, so a round test point keeps a round label area. Any other projection fits the area enclosed by its model drawing's outline lines, the ILLUSTRATION_* drawing; a view with no illustration layer still asks Geometer for it, cached and shared with toon. A footprint whose models give no drawing is fitted to its pads with a warning; a drawing with no outline lines is omitted with a warning. There is no minimum size: every label that fits is drawn, up to max_font_size_mm. Colour, font family, font weight, box_fill_ratio, max_font_size_mm, opacity and the stroke are configurable globally, per view, by exact/prefix/wildcard/range selectors through assembly_designators.selector_overrides, then per component through components entries' assembly_designators, while preserving glyph aspect ratio; show_designator: false hides one. box_fill_ratio is clamped to 0.05 to 1, with a warning for each value outside it. Each label is a <g data-component data-geometry-source="model|pads"> around a <text data-primitive="assembly-designator">, written readable in a mirrored view. min_font_size_mm, rotation_aspect_threshold and rotation_direction are no longer used; a config that sets them loads with a warning.

Known limit: a label fitted to a large union, such as Jumperless SW3 or custom_pads_test AE1, can sit up to about 0.3 mm apart between Python and Rust. The two union libraries give different vertex sets, so the fit tries different candidate points.

HLR

ASSEMBLY_HLR_TOP and ASSEMBLY_HLR_BOTTOM append component assembly geometry after physical and virtual layer composition. KiCad Cruncher computes the KiCad model-to-board transform from the footprint pose, side, board thickness, and model offset/rotation/scale, then passes that complete transform to wn-geometer for STEP projection and model bounds. Fresh defaults generate only assembly_top_view and assembly_bottom_view; those views include board cutouts, drills, slots, pin-1 markers, Geometer outline HLR with a pad-box fallback, and bold monospace assembly designators. The configured modes are outline, detail, bounding_box, model_bounds, pad_bounds, pad_shape, and none. outline is the assembly silhouette mode and defaults to Geometer's fast-mesh-shadow outline algorithm with fast detail projection. Fast output uses polylines; explicit poly/exact selections remain available. Legacy visibility/edge flags require a legacy projection algorithm; fast candidate controls live under assembly_hlr.fast. detail renders the detailed visible projection. bounding_box uses transformed STEP model bounds when a model is available and falls back to pad bounds. model_bounds emits only transformed STEP bounds. pad_bounds emits the box around every pad land on the side's outer copper, non-plated holes and F&B.Cu lands included, and does not require a STEP model. pad_shape outlines each of the part's copper pads on the side in its own shape (circle, rectangle, rounded or chamfered rectangle, oval, trapezoid or custom) and each non-plated hole (circle or slot), unfilled, in the assembly_hlr paint; it does not require a STEP model either. A model whose projection draws nothing falls back to the pad box. A component's assembly_hlr merges over the resolved global/view HLR style for that component.

The mode a part takes in a view is its components entry's projection, else the view's assembly_hlr_mode, else detail, as Altium Cruncher. A standalone ASSEMBLY_HLR_* or ASSEMBLY_DESIGNATORS_* layer output takes the part's projection, else assembly.default_projection (pad_bounds by default). The fixed-mode tokens ASSEMBLY_HLR_*_OUTLINE, ASSEMBLY_HLR_*_DETAIL and ASSEMBLY_BOUNDS_* draw their named mode for every part, over any component projection (owner, 2026-11-25); Altium Cruncher has no such tokens.

Pad geometry follows KiCad, in designator regions, pad boxes and pad_shape outlines. A pad's saved position is relative to its footprint and its saved angle is absolute (pcb_io_kicad_sexpr.cpp), so each pad is turned once. A drill offset moves the copper shape (PAD::ShapePos); the hole, plated or not, stays at the pad position, in DRILLS, SLOTS, the board bores and pad_shape's holes. A pad with a chamfer ratio above 0 or chamfered corners is a chamfered rectangle whatever its shape token, with KiCad's default ratios (0.25 radius, 0.2 chamfer) where the file leaves them out, and is cut as KiCad's TransformRoundChamferedRectToPolygon: each chamfered corner along both edges by the ratio of the shorter side, the other corners as quarter circles. A custom pad's anchor is a circle of diameter size x unless (anchor rect) makes it a rectangle of the pad size, as KiCad's pad default, and its primitives are unioned with it.

A components key that is the designator of a part on the board matches only that part, case-sensitively. Any other key is a selector, matched case-insensitively: a prefix, ending in * or letters only (TP*, TP), or a range <P><n>-<P2><m>, where P is any run of non-digits and P2 is empty or equal to P (U5-U15, U$1-U$9) (owner, 2026-11-25). A selector that is neither a prefix nor a range matches nothing; a range written high to low (U15-U5) still matches. assembly_designators.selector_overrides uses the same matcher. Every entry that matches a designator applies field by field: toon's in-memory generated entry first, then selector keys in file order, a later key over an earlier one, then the exact designator's key. Style mappings (assembly_hlr, assembly_designators, illustration) merge key by key, so an exact entry changes only what it sets.

Assembly part rules (owner, 2026-11-25) decide which parts go to Geometer, which are drawn from their pads and which are left out. They were built from Altium Cruncher's and PCB Engine's heuristics and a survey of the corpus's 9,618 footprints. The rules only write the generated config; the config alone drives the drawing. For each footprint with a designator, the first rule that applies decides, and a designator shared by several parts takes its first part's rule in board file order. A footprint with no Reference value gets no entry and no label:

Partcomponents entryIn the corpus
aA visible 3D model, one not marked hidenone: Geometer
bNo visible model; the footprint draws a line, arc, curve, rectangle, circle or polygon on Edge.Cutsexcluded4: a whole board outline, card-edge fingers, an FPC tail
cboard_onlyexcluded235: stitching vias, logos, placeholder pads, mounting holes
dNo padsexcluded38: logos, screws, nuts, washers
eOne distinct copper pad number, or no copper pads and one or more non-plated holespad_shape589: test points, fiducials, single pads, holes-only mounting holes
fSeveral distinct copper pad numberspad_bounds430: connectors and model-less R, C, JP, NT, U

An exclusion is { "projection": "none", "show_designator": false }. Parts with Edge.Cuts and a model stay with Geometer. The pad count decides, never the designator's name (owner, 2026-11-25), and pads sharing one number count as one pad, as via rings of 17 pads all numbered 1. A hidden-only model counts as no model. Being model-less is normal in KiCad and gets no warning. A part sent to Geometer whose model fails, is not found or draws nothing falls back to the pad box.

A config kcr writes holds these entries in components, grouped in the table's order with one // comment before each non-empty group, each group in board file order and each entry on one line; a board that cannot be read leaves the section empty:

  "components": {
    // Excluded: no 3D model; the footprint draws on Edge.Cuts (board template)
    "JEDEC1": { "projection": "none", "show_designator": false },
    // Excluded: board_only (not in the schematic)
    "LOGO1": { "projection": "none", "show_designator": false },
    // Excluded: no pads and no 3D model
    "MH1": { "projection": "none", "show_designator": false },
    // No 3D model; one pad or holes only: outline in the pad's shape
    "TP1": { "projection": "pad_shape" },
    "H1": { "projection": "pad_shape" },
    // No 3D model; several pads: box around all pads and holes
    "J1": { "projection": "pad_bounds" }
  },

toon, whose config holds no generated entries, applies the same entries in memory beneath its config's components, under any --config. KiCad 11's extruded 3D bodies are not read yet; like Altium's, they should later get an outline in their extruded shape. The default assembly overlay opacity is 0.75.

Geometer projection results expose flattened SVG-ready segments and arcs for outline and detail, plus projected bbox geometry for direct model-bounds callers. KiCad Cruncher uses the outline/detail primitives for component overlays and the model-bounds API for rectangle fallback modes.

Progress

Python and Rust print the same progress lines to standard output. The root --quiet, --verbose and --log-level options set the level, as for toon. On Taillight's default config:

PCB SVG: loading 11-10045__taillight__C.kicad_pro
PCB SVG: loaded 11-10045__taillight__C.kicad_pcb in 0.13s
PCB SVG: writing 2 configured views
PCB SVG: configured view 1/2 assembly_top_view
Preparing top STEP models: 1 unique models
Computing Geometer HLR STEP projection: kicad-embed://FD-3RGB45-N6.stp (hash=6fba88fd9e0b, side=top)
Projecting top components: 1/6 (D1)
Labelling top components: 1/6 (D1)
...
PCB SVG: wrote 2 configured view file(s) in 0.37s
Wrote SVG: <output>\views\11-10045__taillight__C__assembly_bottom_view.svg
Wrote SVG: <output>\views\11-10045__taillight__C__assembly_top_view.svg
PCB SVG timing assembly_top_view: 0.145s

Each assembly HLR layer first counts the side's distinct STEP model files, then reports its side's components at the first and every 25th. Designator layers report Labelling. Each assembly layer first gathers every footprint's projection: cached ones load, and each one to compute prints one line before all of them run together on the worker pool. The layer then places its components. Layer outputs print PCB SVG: writing N physical and M virtual layer outputs and one line per layer; Python writes them before the views and Rust after. SVG paths print sorted, after publication. Per-view and per-layer timings are debug level. The final summary line differs between the languages.

Cache

Geometer HLR projections persist in the kcr cache described for toon. It defaults to .kcr/cache in the project folder (the .kicad_pro's folder, else the board's), --cache-dir moves it, and --no-cache keeps reuse within the run only. A second run on an unchanged board projects nothing and prints no Computing Geometer HLR STEP projection lines. A key covers the Geometer release, C ABI, catalog and engine, the Geometer operation (ipc.model-hlr-projection), the model's SHA-256 and the request. Both languages store the IPC client's HLR projection result A0 as geometer-hlr, version a0, from the same request, so each reuses the other's entries. The request has one view "view" along the side's normal with +Y up, the model's local pose as a row-major model_transform without the footprint rotation (lines turn exactly in 2D under the vertical camera), outline, detail and bounds output, the root placement kept, round_digits (default 3) and only the HLR controls the style sets. Python's earlier geometer-hlr-cli product is retired: a run that stores entries removes it. The output directory must not contain the cache.

Roadmap

Remaining PCB SVG assembly follow-up is tracked by docs/pcb-svg/requirements/pcb-svg-req-001-assembly-validation-and-selectors.md. The active deferred items are manual HLR outline validation on hlr_test and a no-model synthetic pad_bounds test. components selector keys (exact, prefix and range) are in place; list selectors are not. The pcb-svg timing target is open: it is set from Altium Cruncher once both run matched layer lists on FRDM-IMX93 as KiCad (owner, 2026-11-24). Known limits: KiCad 11's extruded 3D bodies are not read, and the repeated-id warning counts differently in the two languages (see ids).

Tests

L0 verifies command registration and help. L3 runs pcb-svg against copied public KiCad corpus boards with explicit kicad_cruncher.pcb_svg.config.a0 files, checking the manifest, layer SVG output, configured view output, virtual cutout extraction, pin-1 marker synthesis, enriched drill metadata, and geometer-backed HLR overlay markers. Those runs pass --no-cache so that tracked and corpus inputs gain no .kcr/; L3_016 covers a second run reusing a persisted projection and pins one geometer-hlr key that Rust's cache tests pin too.

The final success message reports the published output directory after all staged artifacts have been committed.

global.mirror_bottom_view reflects bottom-side configured views horizontally; an explicit per-view mirror value takes precedence and can also reflect a top view. The reflection applies to the completed view, including copper, holes, pin-1 and assembly outlines. Generated assembly labels move with the components while their text stays readable and retains its configured rotation. The SVG data-mirror-x attribute and manifest mirrored value describe the applied view transform. Standalone layer exports retain board-coordinate orientation.