kicad monkey v2026.11.30
On This Page (15)

kcr pcb-svg

Generate configured A0 KiCad PCB SVG design views and optional layer outputs from .kicad_pcb or .kicad_pro files. The command uses <stem>.pcb.svg.config JSON/JSONC configs and supports geometer-backed assembly HLR overlays.

CommandAliasesCategoryRuntimeConfigGuide
kcr pcb-svg—PCB Visualization & Design ReviewPython kcr + Native Rust k3<stem>.pcb.svg.config or pcb.svg.config (kicad_cruncher.pcb_svg.config.a0, auto-created with generated components; inherits sibling fab.jsonc in Python kcr)Rendering & Design Review: kcr pcb-svg

Usage

sh
kcr pcb-svg [-h] [-o OUTPUT] [--config CONFIG]
    [--doc PCBDOC] [--views PCB_VIEWS]
    [--layers PCB_LAYERS] [--scale PCB_SVG_SCALE]
    [--size-unit PCB_SVG_SIZE_UNIT] [--clean-output]
    [--embedded-only] [--cache-dir CACHE_DIR |
    --no-cache] [--workers WORKERS] [--no-color]
    [file]

Native Rust CLI Equivalent (k3)

Implemented natively in k3 on top of kicad-monkey-fab (FabViewData). Both Python kcr pcb-svg and Rust k3 pcb-svg resolve embedded kicad-embed:// STEP models first and fall back to external STEP libraries unless --embedded-only or KCR_EMBEDDED_MODELS_ONLY=1 is set.

sh
k3 pcb-svg [-o OUTPUT] [--config PATH] [--doc BOARD] [--views NAMES] [--layers LAYERS] [--scale SCALE] [--size-unit UNIT] [--clean-output] [--embedded-only] [--workers N] [--cache-dir PATH | --no-cache] [file]

Positional Arguments

ArgumentDescription
fileKiCad PCB or project file; optional when one .kicad_pro/.kicad_pcb is in CWD

Options

FlagDescription
-o, --output OUTPUTOutput directory (default: ./output/pcb-svg)
--config CONFIGPath to kicad_cruncher.pcb_svg.config.a0 JSON/JSONC config. If omitted, pcb-svg uses <stem>.pcb.svg.config beside each input (the .kicad_pro's stem, or a lone board's own), else the folder's pcb.svg.config, writing <stem>.pcb.svg.config with the board's components when neither exists.
--doc, --pcbdoc PCBDOCWith .kicad_pro input, select a specific .kicad_pcb by filename, stem, or path
--views, --pcb-views PCB_VIEWSComma-separated view names plus layers, all, or none
--layers, --pcb-layers PCB_LAYERSComma-separated physical PCB layers when layer outputs are enabled
--scale, --pcb-svg-scale PCB_SVG_SCALESVG display scale for A0 outputs (default: config or 10.0)
--size-unit, --pcb-svg-size-unit PCB_SVG_SIZE_UNITSVG width/height unit suffix for A0 outputs
--clean-outputRequest clean output behavior in the resolved config
--embedded-onlyResolve only kicad-embed:// STEP models; skip external KiCad library paths
--cache-dir CACHE_DIRPersistent cache directory (default: .kcr/cache beside the project or board). Mutually exclusive with --no-cache.
--no-cacheDisable the persistent cache; reuse within this run remains. Mutually exclusive with --cache-dir.
--workers WORKERSGeometer worker processes for model HLR projections, 1 to 64 (default: 4); workers start only for projections missing from the cache
--no-colorDisable ANSI colors and animated spinners

How It Works

kcr pcb-svg is a declarative PCB SVG compositor that renders physical KiCad layers, board domain layers, Geometer 3D STEP HLR outlines, and translucent 3D illustrations in exact draw order. It also composes all 17 canonical FabView virtual layers (VIRTUAL_CUTOUTS, PIN1_*, DIODES_*, CAPACITORS_*, INDUCTORS_*, RESISTORS_*, ASSEMBLY_OUTLINES_*, ASSEMBLY_DESIGNATORS_*, PAD_LABELS_*) alongside BOARD_SUBSTRATE, SOLDERMASK_FILM_*, BOARD_OUTLINE, BOARD_CUTOUTS, DRILLS, and SLOTS.

Outputs are staged into a temporary sibling directory and published atomically into -o <dir> (default ./output/pcb-svg), with a persistent disk cache (.kcr/cache beside the input) reused across runs and variants.

Input & Config Discovery

  1. Input resolution:
    • Accepts .kicad_pcb or .kicad_pro (use --doc <board> to pick a board inside a multi-board project).
    • If omitted, auto-detects a single *.kicad_pro in CWD, falling back to a single *.kicad_pcb.
  2. pcb.svg.config discovery order (auto-creates with board-derived components!):
    1. Explicit --config <path> — if missing, auto-creates a full commented JSONC config pre-populated with generated components entries derived from the board's assembly part rules, then runs with it.
    2. <input_dir>/<stem>.pcb.svg.config — per-board/per-project config (so two boards in the same folder keep separate configs).
    3. <input_dir>/pcb.svg.config — shared folder fallback.
    4. If neither exists, auto-creates <input_dir>/<stem>.pcb.svg.config populated with the board's generated components block.
  3. Read-only sibling fab.jsonc virtual_layers inheritance (Python kcr):
    • If <pcb_dir>/fab.jsonc exists, Python kcr pcb-svg loads and schema-validates it (kicad_cruncher.fab_config.a0), inherits its "virtual_layers" policy underneath any "virtual_layers" block in pcb.svg.config, and strips Gerber-only family *.enabled toggles so disabling a Gerber film never blanks an explicitly requested SVG view (per-component overrides.<REF>.enabled are preserved).
    • Native Rust k3 pcb-svg does not inherit sibling fab.jsonc.

Overlay Rules & Configuration (pcb.svg.config)

Schema contract: kicad_cruncher.pcb_svg.config.a0. User configs are overlaid onto the built-in default template (resources/pcb.svg.default.jsonc) with three important merge rules:

jsonc
{
  "schema": "kicad_cruncher.pcb_svg.config.a0",

  "global": {
    "canvas": {
      "bounds": "board_outline",    // "board_outline" | "all_geometry"
      "margin_mm": 1.0
    },
    "include_metadata": true,       // Emit data-* attributes on SVG elements
    "show_empty_layers": false,
    "clip_to_outline": true,
    "clip_holes_from_copper": true,
    "mirror_bottom_view": true,     // Mirror bottom views for front-reading orientation
    "svg_scale": 10.0,
    "svg_size_unit": "",            // "" | "mm" | "in" | "mil" | "px"
    "clean_output": false,
    "styles": {
      "board_substrate": { "enabled": true, "color": "#B6A26B", "opacity": 1.0 },
      "board_outline": { "enabled": true, "color": "#000000", "line_width_mm": 0.1 },
      "board_cutouts": { "enabled": true, "color": "#880000EE", "hatch": true, "outline_style": "dashed" },
      "drills": { "enabled": true, "plated_color": "#D0D0D0", "non_plated_color": "#ADD8E6" },
      "slots": { "enabled": true, "plated_color": "#D0D0D0", "non_plated_color": "#ADD8E6" },
      "soldermask_film": { "enabled": true, "color": "auto", "opacity": 0.75 },
      "silkscreen_designators": { "enabled": true, "color": "#000000" },
      "pin1_marker": { "enabled": true, "color": "#FF0000BB", "dot_diameter_mm": 0.35 },
      "assembly_designators": {
        "enabled": true,
        "color": "#0094FFA0",
        "font_family": "Consolas, 'Liberation Mono', 'Courier New', monospace",
        "font_weight": "700",
        "box_fill_ratio": 0.8,
        "max_font_size_mm": 5.0
      },
      "assembly_hlr": {
        "enabled": true,
        "color": "#009EFF",
        "line_width_mm": 0.08,
        "projection_algorithm": "fast",          // "fast" | "poly" | "exact"
        "outline_algorithm": "fast-mesh-shadow"  // "fast-mesh-shadow" | "mesh-shadow" | "hlr"
      },
      "illustration": { "enabled": true, "opacity": 0.25, "outline_width_mm": 0.025 }
    }
  },

  "assembly": {
    "default_projection": "pad_bounds", // "detail"|"outline"|"bounding_box"|"model_bounds"|"pad_bounds"|"pad_shape"|"none"
    "dnp_projection": "bounding_box",
    "designator_color": "#0094FFA0",
    "dnp_designator_color": "#FF0000"
  },

  "pin1": {
    "exclude_designators": ["R", "C", "L", "F", "FB", "FU", "SW"],
    "exclude_single_pin": true
  },

  // Per-component overrides (auto-populated on first run from assembly part rules)
  "components": {
    "TP*": { "projection": "pad_shape", "show_designator": true },
    "U5-U15": { "projection": "detail" },
    "J1": { "projection": "outline", "assembly_designators": { "color": "#CC0000" } }
  },

  // Standalone per-layer SVG outputs (disabled by default; enable here OR via --views layers)
  "layer_outputs": {
    "enabled": false,
    "layers": "auto",
    "include_special_layers": ["BOARD_OUTLINE", "BOARD_CUTOUTS", "DRILLS", "SLOTS"],
    "output_dir": "layers"
  },

  "views": [
    {
      "name": "top_assy_view",
      "enabled": true,
      "output_svg": "views/{board}__top_assy_view.svg",
      "layers": [
        "BOARD_OUTLINE", "BOARD_CUTOUTS", "F.Cu", "DRILLS", "SLOTS",
        "F.SilkS", "ASSEMBLY_HLR_TOP", "ILLUSTRATION_TOP",
        "ASSEMBLY_DESIGNATORS_TOP", "PIN1_TOP"
      ],
      "assembly_hlr_mode": "outline",
      "mirror": false,
      "styles": { "silkscreen_designators": { "enabled": false } }
    }
  ]
}

Component Selector & Style Precedence Ladders

1. Assembly Part Rules (Auto-Generated components Entries)

When kcr pcb-svg auto-creates a new config, each footprint with a Reference designator is classified by the first matching rule (repeated designators take the first footprint in board file order):

  1. Has a visible (non-hidden) 3D model -> no entry (projected via Geometer).
  2. No visible model + draws on Edge.Cuts -> projection: "none", show_designator: false.
  3. board_only attribute -> projection: "none", show_designator: false.
  4. No pads at all -> projection: "none", show_designator: false.
  5. Exactly one distinct copper pad number, or NPTH holes only -> projection: "pad_shape".
  6. Otherwise (multiple copper pad numbers) -> projection: "pad_bounds".

2. components Key Matching & Merge Order

Keys in "components" fall into two strict categories:

Merge order (highest wins):

  1. Matching selectors in file order (a later matching selector overrides an earlier one).
  2. Exact board designator key (components.<REF>).

3. Designator Style Cascade (Highest Wins)

  1. Component override components.<REF>.assembly_designators.
  2. Per-view views[i].styles.assembly_designators.
  3. Global global.styles.assembly_designators.
  4. assembly.designator_color (or assembly.dnp_designator_color for DNP parts).

4. Projection Mode Precedence (Highest Wins)

  1. Fixed-mode layer tokens in views[i].layers (ASSEMBLY_HLR_*_OUTLINE, ASSEMBLY_HLR_*_DETAIL, ASSEMBLY_BOUNDS_*_MODEL, ASSEMBLY_BOUNDS_*_PADS) — these force that specific projection regardless of view defaults.
  2. Per-component components.<REF>.projection (resolved via the selector + exact-designator ladder above).
  3. View views[i].assembly_hlr_mode (for composed ASSEMBLY_HLR_TOP/BOTTOM views) or assembly.default_projection (for standalone layer_outputs).

Precedence, Traps & Runtime Guards

  1. The --views vs --layers trap:
    • Passing --layers F.Cu,DIODES_TOP updates layer_outputs.layers, but does NOT turn layer_outputs.enabled on! Because layer_outputs.enabled defaults to false, you must also pass --views layers (or --views top_assy_view,layers, or set layer_outputs.enabled: true in config) for per-layer SVGs to be emitted.
    • --views none disables all composed views and layer_outputs; --views all leaves the config's enabled flags untouched.
  2. 3D STEP model resolution (--embedded-only & KCR_EMBEDDED_MODELS_ONLY=1):
    • Embedded kicad-embed:// STEP payloads are preferred, with automatic fallback to external STEP libraries; pass --embedded-only or set KCR_EMBEDDED_MODELS_ONLY=1 for strict self-contained CI builds. See Embedding 3D STEP Models.
  3. Worker & cache containment guards:
    • --workers N is strictly bounded to 1..64 (default 4).
    • --cache-dir and --no-cache are mutually exclusive. Output and cache paths are checked for unsafe containment so a run never deletes or overwrites its own board, project, config, or cache tree.

Quick Examples

sh
# Render configured top/bottom assembly views
kcr pcb-svg board.kicad_pcb -o output/pcb-svg
sh
# Render selected layers including FabView virtual layers (note: --views layers enables layer_outputs)
kcr pcb-svg board.kicad_pcb --layers F.Cu,DIODES_TOP,PAD_LABELS_TOP --views layers -o output/pcb-svg
sh
# Enforce strict embedded-only 3D models (portable CI mode)
kcr pcb-svg board.kicad_pcb --embedded-only -o output/pcb-svg
sh
# Native Rust binary invocation
k3 pcb-svg board.kicad_pcb -o output/pcb-svg
kicad-monkey v2026.11.30·Docs updated 2026.12.01 15:43 UTC (fd9b75b)