One-Click Hardware Releases: Building a KiCad 9 Production Export Plugin
How to automate complete PCB fabrication releases—Gerbers, drill, pick-and-place, BOM, 3-page assembly PDFs, and 3D renders—using kicad-cli and Python action plugins.
When a printed circuit board layout is complete, translating the CAD database into a manufacturing release package is notoriously error-prone. An engineer must:
- Plot Gerbers across all copper, mask, silk, and paste layers.
- Generate Excellon drill files.
- Export pick-and-place component centroid CSVs.
- Export a STEP 3D model for mechanical enclosure clearance checks.
- Print multi-sheet schematic PDFs and assembly drawings.
- Generate a Bill of Materials (BOM).
- Take high-resolution 3D beauty renders for assembly technicians.
If any single export option is misconfigured (e.g., wrong drill units, forgotten bottom silk, or un-mirrored bottom assembly view), fabrication gets delayed or assembled boards arrive with rotated components.
To make this process foolproof and instant, we built Generate Release Package, a native KiCad 9 Action Plugin that compiles a complete, fab-ready release folder in one click.
1. Zero-Risk Architecture: kicad-cli vs pcbnew API
A major hazard of traditional PCB CAD plugins is that scripts interacting directly with the running application memory (pcbnew.BOARD) can corrupt open layouts or trigger undo-history crashes if an unhandled exception occurs.
Generate Release Package adopts a zero-risk architecture:
[ Active KiCad Layout Session ]
│
(Prompt to Save)
│
▼
[ Saved .kicad_pcb / .kicad_sch on Disk ]
│
▼
Python Plugin shells out to bundled `kicad-cli`
│
├─► kicad-cli pcb export gerbers ...
├─► kicad-cli pcb export drill ...
├─► kicad-cli pcb export pos ...
├─► kicad-cli pcb export pdf (Assembly Top/Bottom) ...
├─► kicad-cli pcb export step ...
├─► kicad-cli sch export pdf ...
└─► kicad-cli sch export bom ...
│
▼
[ Release Files_<Project>_<DDMMYYYY>/ ] (Opened in Explorer)
Because all export tasks are performed by kicad-cli (the standalone command-line binary bundled with KiCad 9), the live board is never modified, memory is isolated, and exports run at compiled C++ speed.
2. Standardized Output Directory Structure
The plugin bundles every asset required by fabrication and assembly facilities into a self-documenting directory:
Release Files_<Project>_<DDMMYYYY>/
├── Board_Information.CSV # Board dimensions, layer count, pad count
├── Assembly_Files/
│ ├── Assembly Drawings.PDF # 3-page PDF: Overview + Top + Bottom views
│ ├── Top PCB 3D Print.png # 3000x2400 high-res top render
│ └── Bottom PCB 3D Print.png # 3000x2400 high-res bottom render
├── Bill Of Materials/
│ └── <Project>_BOM.CSV # Clean CSV (Refs, Value, Footprint, MPN)
├── Fabrication_Files/
│ ├── Gerbers/ # Standard RS-274X copper, mask, silk layers
│ └── Drill/ # Plated & non-plated Excellon drill files
├── Mechanical_3D/
│ └── <Project>.STEP # Unified AP214/AP242 STEP assembly
├── Pick and Place/
│ └── <Project>_all_pos.csv # SMT machine centroid data (X, Y, Rotation)
└── Schematics/
└── <Project>_Schematic.PDF # Full vector schematic document
3. The 3-Page Assembly Drawing PDF
Assembly technicians need clear graphical component references. The plugin automatically synthesizes a 3-page vector assembly drawing formatted with clean title blocks:
- Page 1 (Overview & Mechanical Specs): Side-by-side Top and Bottom previews, board dimensions ($X \times Y$), overall thickness, copper weight, surface finish, and primary component counts.
- Page 2 (ASSEMBLY TOP): Vector drawing of top silkscreen, pads, and component reference designators (
R1,C1,U1), with non-populated parts crossed out. - Page 3 (ASSEMBLY BOTTOM): Mirrored vector view of the bottom layer for effortless benchtop inspection.
def generate_assembly_pdf(board_path, output_pdf):
"""Executes kicad-cli pcb export pdf with assembly layer presets."""
cmd = [
"kicad-cli", "pcb", "export", "pdf",
"--layers", "F.Fab,F.CrtYd,Edge.Cuts",
"--black-and-white",
"--include-border-title",
"-o", output_pdf,
board_path
]
subprocess.run(cmd, check=True)
4. Selective Export GUI
Engineers don’t always need every output during mid-layout reviews. The plugin opens a lightweight wxWidgets dialog:
- Independent checkboxes for Gerbers, Drill, Centroids, Assembly PDF, 3D Renders, STEP, BOM, and Schematic.
- Select All and Deselect All hotkeys.
- Destination folder picker (defaults to project directory or desktop).
When execution finishes, the plugin calculates board statistics (total SMT pads, through-holes, and dimensions) into Board_Information.CSV and automatically opens the output directory in Windows File Explorer via os.startfile.
The result: a release package that used to take 45 minutes of repetitive clicking is generated in under 15 seconds with zero human error.