Skip to main content

Overview

Action plugins allow you to extend KiCad’s PCB editor with custom interactive tools. They appear as menu items and optional toolbar buttons, providing a way to automate repetitive tasks or add new functionality.

Plugin Architecture

Action plugins are implemented through the ACTION_PLUGIN base class defined in /pcbnew/action_plugin.h:

Creating an Action Plugin

Basic Structure

Create a Python file that inherits from ActionPlugin:

Plugin Metadata

The defaults() method sets plugin properties:
  • name: Display name in menu (required)
  • category: Submenu grouping (required)
  • description: Tooltip and help text (required)
  • show_toolbar_button: Add to toolbar (default: False)
  • icon_file_name: Path to icon (24x24 PNG recommended)
  • dark_icon_file_name: Icon for dark theme (optional)

Real-World Examples

Example 1: Automatic Border Creator

Based on /demos/python_scripts_examples/action_menu_add_automatic_border.py:

Example 2: Footprint Generator

Based on /demos/python_scripts_examples/action_plugin_test_undoredo.py:

Example 3: Move Items Randomly

Plugin Management

The ACTION_PLUGINS class manages all registered plugins:

Plugin Installation

Directory Structure

Plugins are loaded from these directories (in order):
  1. Stock plugins: <kicad>/scripting/plugins/
  2. User plugins: ~/.kicad/scripting/plugins/ (Linux/macOS)
  3. User plugins: %APPDATA%/kicad/scripting/plugins/ (Windows)
  4. Third-party: $KICAD_3RD_PARTY/plugins/

File Organization

Loading Process

Plugins are automatically loaded on startup via LoadPlugins() in /scripting/kicadplugins.i:

Undo/Redo Support

Action plugins automatically support undo/redo when using proper methods:

Icon Guidelines

  • Size: 24x24 pixels (PNG format)
  • Style: Monochrome or simple colors
  • Transparency: Use alpha channel for toolbar integration
  • Dark theme: Provide dark_icon_file_name for dark mode

Debugging

Error Handling

Logging

Avoid using print() as it can cause IO exceptions. Use wx dialogs or write to files instead.

Best Practices

  1. Always call Refresh(): Update the display after modifications
  2. Use GetBoard(): Don’t cache the board object
  3. Handle errors gracefully: Wrap code in try/except blocks
  4. Validate inputs: Check that board elements exist before accessing
  5. Use proper units: Always convert with FromMM() or FromMils()
  6. Test undo/redo: Ensure your plugin works with the undo system
  7. Avoid blocking operations: Long operations should show progress

Common Issues

Plugin Not Loading

Check PLUGIN_DIRECTORIES_SEARCH and NOT_LOADED_WIZARDS:
Ensure you:
  • Called .register() at module level
  • Implemented all required methods
  • Returned valid strings from metadata methods

See Also