pcbnew module.
Getting Started
Import the pcbnew module to access the Python API:Core Functions
Board Management
LoadBoard(filename, format=None)
Loads a board from file.
Parameters:
filename(str): Path to the board fileformat(PCB_IO_MGR.PCB_FILE_T, optional): File format specifier
BOARD object or None if loading fails
GetBoard()
Returns the currently active board in the PCB editor.
Returns: BOARD object or None
CreateEmptyBoard()
Constructs a default BOARD with a temporary project.
Returns: New BOARD object
NewBoard(filename)
Creates a new board and project with the given filename (will overwrite existing files).
Parameters:
filename(str): Full path for the new board file
BOARD object or None
SaveBoard(filename, board, skipSettings=False)
Saves a board to file in KiCad native format.
Parameters:
filename(str): Target file pathboard(BOARD): Board object to saveskipSettings(bool): IfTrue, only save the board file (loses project settings)
True if successful, False otherwise
Drawing and Plotting
PLOT_CONTROLLER(board)
Creates a plot controller for generating output files.
Parameters:
board(BOARD): Board to plot
Plot Options Methods
SetOutputDirectory(dir)- Set output directory for plot filesSetPlotFrameRef(bool)- Enable/disable frame reference plottingSetSketchPadLineWidth(width)- Set pad line width for sketch modeSetAutoScale(bool)- Enable/disable auto-scalingSetScale(scale)- Set plot scale (typically 1)SetMirror(bool)- Enable/disable mirroringSetUseGerberAttributes(bool)- Include Gerber X2 attributesSetIncludeGerberNetlistInfo(bool)- Include netlist informationSetCreateGerberJobFile(bool)- Generate .gbrjob fileSetUseAuxOrigin(bool)- Use auxiliary originSetPlotReference(bool)- Plot component referencesSetPlotValue(bool)- Plot component valuesSetSubtractMaskFromSilk(bool)- Remove soldermask from silkscreenSetDrillMarksType(type)- Set drill mark style
Drill File Generation
EXCELLON_WRITER(board)
Creates a drill file writer.
Library Management
GetFootprintLibraries()
Returns all configured footprint library nicknames.
Returns: wxArrayString of library nicknames
GetFootprints(nickname)
Returns all footprint names in a library.
Parameters:
nickname(str): Library nickname
wxArrayString of footprint names
Utility Functions
Unit Conversion
Refresh()
Updates the board display after modifications.
UpdateUserInterface()
Updates layer manager and widgets from board setup.
GetUserUnits()
Returns the current user unit setting.
Returns: 0 for inches, 1 for mm, -1 if frame not set
GetCurrentSelection()
Returns currently selected board items.
Returns: deque of BOARD_ITEM objects
FocusOnItem(item, layer=UNDEFINED_LAYER)
Focuses the view on a specific board item.
Parameters:
item(BOARD_ITEM): Target itemlayer(PCB_LAYER_ID): Layer ID (optional)
DRC and Validation
WriteDRCReport(board, filename, units, reportAllTrackErrors)
Runs DRC check and writes results to a report file.
Parameters:
board(BOARD): Board to checkfilename(str): Output report pathunits(EDA_UNITS): Units for reportreportAllTrackErrors(bool): Report all errors or just first per track
True if successful
BOARD Class
TheBOARD class represents a PCB design.
Common Methods
Layer Constants
Common layer identifiers:Plot Format Constants
Complete Example: Board Export
See Also
- Plugin API - Creating action plugins
- CLI Reference - Command-line automation
- IPC Protocol - API server communication