kicad monkey v2026.11.30
On This Page (10)

kcr fab

Generate analytic fabrication outputs directly from KiCadFabView: Gerber X2/X1, Excellon NC drill, IPC-2581 Rev B, Pick-and-Place, BOM, pure-Python Micro-STEP, and all 17 virtual fab layers.

CommandAliasesCategoryRuntimeConfigGuide
kcr fabkcr gerbz, kcr ipc2581Fabrication & Manufacturing OutputsPython kcr + Native Rust k3fab.jsonc (kicad_cruncher.fab_config.a0, auto-created beside the board unless --dry-run)Fabrication & Outputs: kcr fab

Usage

sh
kcr fab [-h] [--doc PCBDOC] [--config CONFIG]
    [--init-config] [--force-config] [-o OUTPUT]
    [--stem STEM] [--variant VARIANT] [--gerbers]
    [--no-gerbers] [--ipc2581] [--pnp] [--bom]
    [--micro-step] [--virtual-layers VIRTUAL_LAYERS]
    [--no-virtual-layers] [--bake] [--force-bake]
    [--examples EXAMPLES] [--dry-run] [--no-color]
    [file]

Native Rust CLI Equivalent (k3)

Implemented natively in the standalone k3 Rust binary (kicad-cruncher-cli) on top of kicad-monkey-fab (FabViewData). See the Native Rust CLI (k3) Parity Guide for flag-level differences (such as k3's separate --drill/--no-drill toggles).

sh
k3 fab [--doc PCBDOC] [--config CONFIG] [--init-config] [--force-config] [-o OUTPUT] [--stem STEM] [--variant VARIANT] [--all] [--gerbers | --no-gerbers] [--drill | --no-drill] [--ipc2581] [--svg] [--layer-svgs] [--pnp] [--bom] [--micro-step] [--virtual-layers LIST | --no-virtual-layers] [--bake] [--force-bake] [--dry-run] [--aux-origin] [--no-silk] [--x1] [file]

Positional Arguments

ArgumentDescription
fileInput .kicad_pcb or .kicad_pro (auto-detects single board/project in cwd)

Options

FlagDescription
--doc PCBDOCBoard filename/stem when input is .kicad_pro
--config CONFIGPath to fab.jsonc
--init-configWrite a commented default fab.jsonc template and exit
--force-configOverwrite an existing config file when used with --init-config
-o, --output OUTPUTOutput directory (default: ./output/fab)
--stem STEMOverride output filename stem
--variant VARIANTBoard assembly variant name
--gerbersEnable Gerber + NC Drill outputs
--no-gerbersDisable Gerber + NC Drill outputs
--ipc2581Enable IPC-2581 Rev B (.cvg) output
--pnpEnable Pick-and-Place CSV output
--bomEnable BOM CSV output
--micro-stepEnable pure-Python Micro-STEP output
--virtual-layers VIRTUAL_LAYERSComma-separated canonical virtual layer keys to emit (e.g. CUTOUTS,PIN1_TOP,DIODES_TOP)
--no-virtual-layersDisable all virtual layers and profile cutout callouts
--bakeAlso bake configured virtual layers onto KiCad User.* layers in the board
--force-bakeOverwrite occupied KiCad User.* layers when --bake is set
--examples EXAMPLESMax diagnostic examples printed per code (default: 3)
--dry-runCompute all outputs and report counts without writing files
--no-colorDisable ANSI colors and animated spinners

How It Works

kcr fab lowers a KiCad PCB (.kicad_pcb or .kicad_pro) through KiCadFabView into a clean manufacturing release tree under -o <dir> (default ./output/fab):

Re-runs are clean by default: before writing new Gerber or NC drill sets, kcr fab removes stale files from prior runs for the same <stem> (both filenames recorded in <stem>.fab-report.json and standard Gerber/Excellon extensions matching <stem>).

Input & Config Discovery

  1. Board / project input:
    • Pass a .kicad_pcb or .kicad_pro path explicitly (use --doc <board> to pick one board inside a multi-board .kicad_pro).
    • If omitted, kcr fab checks the current working directory for a single *.kicad_pro, falling back to a single *.kicad_pcb. Ambiguous or empty directories fail with exit code 1.
  2. fab.jsonc resolution order:
    1. --init-config writes a commented template to --config <path> (or ./fab.jsonc) and exits immediately (--force-config overwrites an existing file).
    2. Explicit --config <path> — errors if missing (never auto-creates).
    3. Sibling <pcb_dir>/fab.jsonc — loaded automatically if present.
    4. Otherwise, if --dry-run is not set, kcr fab auto-creates <pcb_dir>/fab.jsonc with KiCad-native defaults and runs with it. Under --dry-run, in-memory defaults are used without writing any file.

Configuration (fab.jsonc)

Schema contract: kicad_cruncher.fab_config.a0. Comments (//, /* ... */) and trailing commas are supported. Its "virtual_layers" block is also inherited read-only by sibling kcr vdoc, kcr pcb-svg, and kcr toon runs.

jsonc
{
  "schema": "kicad_cruncher.fab_config.a0",

  "gerbers": {
    "enabled": true,
    "x2_attributes": true,          // false for legacy RS-274X (X1)
    "datum": "user",                // "user" (KiCad aux origin) | "absolute"
    "decimal_digits": 6,
    "profile": true,                // Board perimeter film (.GM1)
    "profile_cutouts": true,        // Draw cutout hatching & labels on the profile film
    "keepout": false,               // Altium-style keepout film (.GKO); off by default
    "pad_masters": false,           // Optional pad-master films
    "drill_guide": false,           // Optional drill-guide films
    "drill_drawing": false,         // Optional drill-drawing films
    // "mechanical_layers": ["User.Drawings"],
    // "extensions": { "PROFILE": "GKO" }, // Remap by canonical key OR default extension
    // "virtual_layers": ["CUTOUTS", "PIN1_TOP", "PIN1_BOTTOM", "DIODES_TOP", "DIODES_BOTTOM"]
  },

  "nc_drill": {
    "enabled": true,
    "datum": "user",                // "user" | "absolute"
    "decimal_digits": 4,
    "board_edge_rout": false        // Emit optional board-outline routing file
  },

  "ipc2581": {
    "enabled": false,
    "negative_standoffs": "zero"    // "zero" | "as_saved"
    // "document_layers": ["F.Fab", "B.Fab"],
    // "virtual_layers": ["CUTOUTS", "PIN1_TOP", "PIN1_BOTTOM"]
  },

  "pnp": {
    "enabled": false,
    "units": "mm"                   // "mm" | "mil"
  },

  "bom": {
    "enabled": false
  },

  "micro_step": {
    "enabled": false,
    // "layers": ["TOP"],           // First entry selects the Micro-STEP copper layer (default "TOP")
    "include_board_outline": true,
    "include_cutouts": true,
    "include_drills": true
  },

  "bake_to_pcb": {
    "enabled": false,               // Opt-in board baking (also enabled by --bake)
    "backup": true,                 // Save <board>.kicad_pcb.bak before in-place write
    "clear_existing": true,         // Replace prior Virtual_* groups
    "layers": {}                    // Optional virtual-key -> KiCad layer overrides
  },

  // Shared across kcr fab, kcr vdoc, kcr pcb-svg, and kcr toon (17 canonical layers).
  "virtual_layers": {
    "font_mode": "stroke",          // "stroke" | "truetype"
    "stroke_font": "default",       // "sans_serif" | "serif" | "default" (omitted config / --dry-run without fab.jsonc falls back to "sans_serif")
    "font_family": "Arial",         // Used when font_mode is "truetype"
    "font_bold": true,
    "dnp_mode": "omit",             // "omit" | "crossout"

    "visibility": {
      "exclude_kinds": ["graphical", "net_tie"],
      "exclude_designator_prefixes": [],
      "outline_parameter": "ASSEMBLY_OUTLINE",
      "designator_parameter": "ASSEMBLY_DESIGNATOR",
      "pin1_parameter": "PIN1_MARKER",
      "pad_labels_parameter": "PAD_LABELS",
      "diode_parameter": "DIODE_SYMBOL",
      "capacitor_parameter": "CAPACITOR_SYMBOL",
      "inductor_parameter": "INDUCTOR_SYMBOL",
      "resistor_parameter": "RESISTOR_SYMBOL",
      "overrides": {}               // Per-designator family booleans, e.g. { "U1": { "pin1": true } }
    },
    "cutouts": {
      "enabled": true,
      "on_profile": true,
      "scope": "interior",          // "interior" | "all"
      "hatch": true,
      "hatch_angle_deg": 45.0,
      "hatch_pitch_mm": 1.0,
      "label": "CUTOUT"
    },
    "pin1": {
      "enabled": true,
      "visibility_mode": "all",     // "all" | "explicit"
      "style": "dot",               // "dot" | "square" | "pad" | "pin_label"
      "knockout": false,
      "exclude_designator_prefixes": ["R", "C", "L", "F", "FB", "FU", "SW"],
      "exclude_two_pin_prefixes": ["X", "Y"],
      "diode_ak_labels": true,
      "cap_polarity_labels": true,
      "inductor_polarity_markers": true,
      "label_orientation": "pad"    // "pad" | "orthogonal" | "upright"
    },
    "diodes": {
      "enabled": true,
      "visibility_mode": "all",     // "all" | "explicit"
      "color_mode": "shaded"        // "shaded" | "monochrome"
    },
    "capacitors": {
      "enabled": false,
      "visibility_mode": "polarized_only" // "all" | "polarized_only" | "explicit"
    },
    "inductors": {
      "enabled": false,
      "visibility_mode": "polarized_only" // "all" | "polarized_only" | "explicit"
    },
    "resistors": {
      "enabled": false,
      "visibility_mode": "all",
      "style": "zigzag"             // "zigzag" | "box"
    },
    "assembly_outlines": {
      "enabled": true,
      "visibility_mode": "all",
      "detail": "simple"            // "simple" | "detail" | "bounding_box"
    },
    "assembly_designators": {
      "enabled": true,
      "visibility_mode": "all",
      "oblique_min_aspect_ratio": 1.2
    },
    "pad_labels": {
      "enabled": false,
      "visibility_mode": "all",
      "orientation": "pad",         // "pad" | "orthogonal" | "upright"
      "knockout": false,
      "skip_mechanical_pads": false,
      "include_through_hole": true
    }
  }
}
note

Deprecated include_non_polarized bridge For capacitors and inductors, legacy include_non_polarized: true is automatically normalized to visibility_mode: "all" (and false to "polarized_only") per config layer before merging. If both keys appear in the same layer, explicit visibility_mode wins.

Precedence & Conflict Rules

Every CLI flag and alias resolves in strict order so scripted runs are deterministic:

  1. Command alias overrides:
    • kcr ipc2581 forces ipc2581 on and turns off both Gerbers and NC Drill unless you explicitly pass --gerbers.
    • kcr gerbz forces both Gerbers and NC Drill on (other config-enabled outputs such as pnp or bom still follow fab.jsonc unless disabled there).
  2. --gerbers vs --no-gerbers (sequential, not mutually exclusive):
    • In Python kcr fab, --gerbers and --no-gerbers are evaluated sequentially rather than as an argparse mutex, and both toggle Gerber and NC Drill together.
    • If both flags are passed on the same command line, --no-gerbers wins because it is applied last. (In native Rust k3 fab, --gerbers/--no-gerbers and --drill/--no-drill are independent toggles.)
  3. Additive output flags:
    • --ipc2581, --pnp, --bom, --micro-step, and --bake only turn their respective outputs on over fab.jsonc; they never turn off outputs enabled in fab.jsonc.
  4. Virtual-layer selection ladder (highest wins):
    1. --no-virtual-layers — empties the virtual layer set and forces gerbers.profile_cutouts = False.
    2. --virtual-layers <CSV> (repeatable) — replaces both gerbers.virtual_layers and ipc2581.virtual_layers. Unknown keys fail with exit code 1.
    3. Per-output gerbers.virtual_layers / ipc2581.virtual_layers arrays in fab.jsonc (when non-null).
    4. Family virtual_layers.<family>.enabled defaults in fab.jsonc.
  5. Gerber filename & extension collision guards:
    • Board PROFILE defaults to .GM1, which collides with MECHANICAL1 if both are emitted simultaneously. Likewise, remapping PROFILE to GKO collides if gerbers.keepout: true is also active.
    • gerbers.extensions accepts either a canonical key ("PROFILE": "GKO") or a default extension ("GM1": "GKO"). Conflicting mappings or two emitted layers resolving to the same <stem>.<EXT> filename fail fast rather than silently overwriting a film.
  6. Stale-output pruning:
    • Writing Gerbers unlinks prior files listed under outputs.gerbers.files in <stem>.fab-report.json plus any <stem>.G* Gerber matching the built-in extension regex. Writing drills unlinks prior outputs.nc_drill.files plus matching <stem>*.DRL / <stem>*.TX* files. Files for other board stems in the same folder are untouched.
  7. --bake collision guard vs --force-bake:
    • Before baking (--bake or bake_to_pcb.enabled: true), kcr fab inspects target KiCad layers for existing non-virtual artwork. If any target layer is occupied, baking aborts with exit code 1 unless --force-bake is passed.
    • Under --dry-run, baking computes counts without saving the board or .bak backup.

Quick Examples

sh
# Generate a starter commented fab.jsonc template
kcr fab --init-config --config fab.jsonc
sh
# Write Gerber X2 + Excellon NC drill + enabled virtual fab layers
kcr fab board.kicad_pcb -o output/fab
sh
# Emit IPC-2581B, Pick-and-Place, BOM, and Micro-STEP
kcr fab board.kicad_pcb --ipc2581 --pnp --bom --micro-step -o output/fab
sh
# Alias shorthands
kcr gerbz board.kicad_pcb -o output/gerbers
kcr ipc2581 board.kicad_pcb -o output/ipc2581
kicad-monkey v2026.11.30·Docs updated 2026.12.01 15:43 UTC (fd9b75b)