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.
| Command | Aliases | Category | Runtime | Config | Guide |
|---|---|---|---|---|---|
kcr fab | kcr gerbz, kcr ipc2581 | Fabrication & Manufacturing Outputs | Python kcr + Native Rust k3 | fab.jsonc (kicad_cruncher.fab_config.a0, auto-created beside the board unless --dry-run) | Fabrication & Outputs: kcr fab |
Usage
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).
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
| Argument | Description |
|---|---|
file | Input .kicad_pcb or .kicad_pro (auto-detects single board/project in cwd) |
Options
| Flag | Description |
|---|---|
--doc PCBDOC | Board filename/stem when input is .kicad_pro |
--config CONFIG | Path to fab.jsonc |
--init-config | Write a commented default fab.jsonc template and exit |
--force-config | Overwrite an existing config file when used with --init-config |
-o, --output OUTPUT | Output directory (default: ./output/fab) |
--stem STEM | Override output filename stem |
--variant VARIANT | Board assembly variant name |
--gerbers | Enable Gerber + NC Drill outputs |
--no-gerbers | Disable Gerber + NC Drill outputs |
--ipc2581 | Enable IPC-2581 Rev B (.cvg) output |
--pnp | Enable Pick-and-Place CSV output |
--bom | Enable BOM CSV output |
--micro-step | Enable pure-Python Micro-STEP output |
--virtual-layers VIRTUAL_LAYERS | Comma-separated canonical virtual layer keys to emit (e.g. CUTOUTS,PIN1_TOP,DIODES_TOP) |
--no-virtual-layers | Disable all virtual layers and profile cutout callouts |
--bake | Also bake configured virtual layers onto KiCad User.* layers in the board |
--force-bake | Overwrite occupied KiCad User.* layers when --bake is set |
--examples EXAMPLES | Max diagnostic examples printed per code (default: 3) |
--dry-run | Compute all outputs and report counts without writing files |
--no-color | Disable 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):
gerbers/— analytic RS-274X Gerber X2 (or X1) films, enabled virtual layers, and Excellon NC drill/slot files.ipc2581/— single-file IPC-2581 Rev B (.cvg) package when enabled.assembly/— Pick-and-Place CSV and/or BOM CSV when enabled.step/— pure-Python ISO 10303-21 Micro-STEP (<stem>__micro.step) when enabled.<stem>.fab-report.json(kicad_cruncher.fab_report.a0) — machine-readable summary of every emitted file, item count, warning/error code tally, and timing.
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
- Board / project input:
- Pass a
.kicad_pcbor.kicad_propath explicitly (use--doc <board>to pick one board inside a multi-board.kicad_pro). - If omitted,
kcr fabchecks the current working directory for a single*.kicad_pro, falling back to a single*.kicad_pcb. Ambiguous or empty directories fail with exit code1.
- Pass a
fab.jsoncresolution order:--init-configwrites a commented template to--config <path>(or./fab.jsonc) and exits immediately (--force-configoverwrites an existing file).- Explicit
--config <path>— errors if missing (never auto-creates). - Sibling
<pcb_dir>/fab.jsonc— loaded automatically if present. - Otherwise, if
--dry-runis not set,kcr fabauto-creates<pcb_dir>/fab.jsoncwith 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.
{
"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
}
}
}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:
- Command alias overrides:
kcr ipc2581forcesipc2581on and turns off both Gerbers and NC Drill unless you explicitly pass--gerbers.kcr gerbzforces both Gerbers and NC Drill on (other config-enabled outputs such aspnporbomstill followfab.jsoncunless disabled there).
--gerbersvs--no-gerbers(sequential, not mutually exclusive):- In Python
kcr fab,--gerbersand--no-gerbersare 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-gerberswins because it is applied last. (In native Rustk3 fab,--gerbers/--no-gerbersand--drill/--no-drillare independent toggles.)
- In Python
- Additive output flags:
--ipc2581,--pnp,--bom,--micro-step, and--bakeonly turn their respective outputs on overfab.jsonc; they never turn off outputs enabled infab.jsonc.
- Virtual-layer selection ladder (highest wins):
--no-virtual-layers— empties the virtual layer set and forcesgerbers.profile_cutouts = False.--virtual-layers <CSV>(repeatable) — replaces bothgerbers.virtual_layersandipc2581.virtual_layers. Unknown keys fail with exit code1.- Per-output
gerbers.virtual_layers/ipc2581.virtual_layersarrays infab.jsonc(when non-null). - Family
virtual_layers.<family>.enableddefaults infab.jsonc.
- Gerber filename & extension collision guards:
- Board
PROFILEdefaults to.GM1, which collides withMECHANICAL1if both are emitted simultaneously. Likewise, remappingPROFILEtoGKOcollides ifgerbers.keepout: trueis also active. gerbers.extensionsaccepts 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.
- Board
- Stale-output pruning:
- Writing Gerbers unlinks prior files listed under
outputs.gerbers.filesin<stem>.fab-report.jsonplus any<stem>.G*Gerber matching the built-in extension regex. Writing drills unlinks prioroutputs.nc_drill.filesplus matching<stem>*.DRL/<stem>*.TX*files. Files for other board stems in the same folder are untouched.
- Writing Gerbers unlinks prior files listed under
--bakecollision guard vs--force-bake:- Before baking (
--bakeorbake_to_pcb.enabled: true),kcr fabinspects target KiCad layers for existing non-virtual artwork. If any target layer is occupied, baking aborts with exit code1unless--force-bakeis passed. - Under
--dry-run, baking computes counts without saving the board or.bakbackup.
- Before baking (
Quick Examples
# Generate a starter commented fab.jsonc template
kcr fab --init-config --config fab.jsonc# Write Gerber X2 + Excellon NC drill + enabled virtual fab layers
kcr fab board.kicad_pcb -o output/fab# Emit IPC-2581B, Pick-and-Place, BOM, and Micro-STEP
kcr fab board.kicad_pcb --ipc2581 --pnp --bom --micro-step -o output/fab# Alias shorthands
kcr gerbz board.kicad_pcb -o output/gerbers
kcr ipc2581 board.kicad_pcb -o output/ipc2581