Plugin Types
Action Plugins
Action plugins add custom commands to the PCB editor menu and toolbar. They can modify the board, perform calculations, or interact with external tools.Footprint Wizard Plugins
Footprint wizards generate parametric footprints based on user-defined parameters.Action Plugins
Basic Structure
Create a class that inherits frompcbnew.ActionPlugin:
ActionPlugin Class Reference
Required Methods
defaults()
Defines plugin metadata. Must set:
self.name(str) - Display name in menuself.category(str) - Menu category/submenuself.description(str) - Detailed description
Run()
Executed when the plugin is activated. Contains the main plugin logic.
Optional Properties
show_toolbar_button (bool)
If True, adds a button to the top toolbar. Default: False
icon_file_name (str)
Path to icon file for light theme (PNG format recommended).
dark_icon_file_name (str)
Path to icon file for dark theme. Falls back to icon_file_name if not set.
Inherited Methods
GetName() → str
Returns the plugin name.
GetCategoryName() → str
Returns the category name.
GetDescription() → str
Returns the plugin description.
GetClassName() → str
Returns the Python class name.
GetShowToolbarButton() → bool
Returns whether toolbar button is shown.
GetIconFileName(dark) → str
Returns the appropriate icon file path.
Parameters:
dark(bool) - IfTrue, returns dark theme icon
GetPluginPath() → str
Returns the path where the plugin was loaded from.
Plugin Discovery
KiCad searches for plugins in these locations:- Bundled plugins:
<kicad_installation>/scripting/plugins/ - User plugins:
<user_config>/scripting/plugins/ - Third-party plugins:
$KICAD_3RD_PARTY/plugins/
- Be a
.pyfile (e.g.,my_plugin.py) - Be a directory containing
__init__.py(e.g.,my_plugin/__init__.py)
Example: Add Date to PCB
Example: Automatic Border
This plugin adds a border around the board edge:Footprint Wizard Plugins
Basic Structure
Parameter Types
Use these constants for parameter units:pcbnew.uMM- Millimeterspcbnew.uMils- Mils (thousandths of an inch)pcbnew.uFloat- Floating point numberpcbnew.uInteger- Integerpcbnew.uBool- Booleanpcbnew.uRadians- Radianspcbnew.uDegrees- Degreespcbnew.uPercent- Percentagepcbnew.uString- String
FootprintWizardParameter Class
Parameters are defined using:page(str) - Parameter page/group namename(str) - Parameter nameunit(str) - Unit type (from constants above)default- Default valuehint(str, optional) - Tooltip textdesignator(str, optional) - Short designator (e.g., “e”, “D”)min_value(optional) - Minimum allowed valuemax_value(optional) - Maximum allowed valuemultiple(int, optional) - For integers, value must be multiple of this
Accessing Parameters
Use theparameters property to access parameter values:
Plugin Loading
KiCad loads plugins at startup using theLoadPlugins() function:
- Searches plugin directories
- Imports Python modules
- Tracks dependencies
- Handles errors and reports failures
Plugin Reload
Plugins are automatically reloaded when:- Modified files are detected
- KiCad restarts
- Forced reload is triggered
Error Handling
Failed plugins are tracked in:Best Practices
1. Error Handling
Wrap plugin code in try-except blocks:2. Avoid Print Statements
Print statements can cause I/O exceptions when KiCad runs without a console. Use logging or write to files instead.3. Refresh After Modifications
Always callpcbnew.Refresh() after modifying the board:
4. Check IsActionRunning
Prevent recursive plugin execution:5. Use Relative Paths
For icons and resources, use paths relative to the plugin file:C++ Plugin API
The underlying C++ API defines these base classes:ACTION_PLUGIN
Abstract base class for action plugins. Pure virtual methods:GetCategoryName()→ wxStringGetName()→ wxStringGetClassName()→ wxStringGetDescription()→ wxStringGetShowToolbarButton()→ boolGetIconFileName(bool aDark)→ wxStringGetPluginPath()→ wxStringGetObject()→ void*Run()→ void
register_action()- Register with plugin manager
ACTION_PLUGINS
Static manager for all action plugins. Static methods:register_action(ACTION_PLUGIN*)- Register a pluginderegister_object(void*)- Deregister by object pointerGetAction(wxString)→ ACTION_PLUGIN* - Get by nameGetAction(int)→ ACTION_PLUGIN* - Get by indexGetActionsCount()→ int - Get countIsActionRunning()→ bool - Check if any action is runningSetActionRunning(bool)- Set running stateUnloadAll()- Unload all plugins
See Also
- Python API - Core Python scripting reference
- CLI Reference - Command-line automation
- IPC Protocol - External process communication