Hi all,
A new feature is now available for testing in KiCad daily build (PPA Ubuntu).
This feature allow you to create a menuentry on pcbnew at this place:
This new menu entry will call a python action/plugin.
To use it:
Compilation option
Be sure to use KiCad with KICAD_SCRIPTING_ACTION_MENU option activated (this is the case for PPA Ubuntu since yesterday).
Install the plugin
The following script is an example:
import pcbnew import re import datetime class text_by_date( pcbnew.ActionPlugin ): def defaults( self ): self.name = "Add date on PCB" self.category = "Modify PCB" self.description = "Automaticaly add date on an existing PCB" def Run( self ): pcb = pcbnew.GetBoard() for draw in pcb.m_Drawings: if draw.GetClass() == 'PTEXT': txt = re.sub( "\$date\$ [0-9]{4}-[0-9]{2}-[0-9]{2}", "$date$", draw.GetText() ) if txt == "$date$": draw.SetText( "$date$ %s"%datetime.date.today() ) text_by_date().register()
This example script is took from sources:
kicad/demos/python_scripts_examples/action_menu_text_by_date.py
If package kicad-demo is installed, a copy is present at
/usr/share/kicad/demos/python_scripts_examples/action_menu_text_by_date.py
Copy (or create) this file at the right places to install it:
- Single user installation (home directory based): ~/.kicad_plugins/
- System wide: /usr/share/kicad/scripting/plugins/
After this, you can refresh plugin list (or restart kicad). A new menu entry is available:
Use the plugin
This (small) example plugin try to find any text field on the board file and if the text is ā$date$ā, it automaticaly change it by ā$date$ā + the current date.
Example:
Before:
After:
Of course this example is really trivial. Anyway you can imaginate a large number of things with the python interface.
Keep in mind that python interface is not completly stable and your scripts needs to be written with care !
In KiCad demo there are 3 example provided:
- action_menu_text_by_date.py: The example above
- action_menu_add_automatic_border.py: An example to automaticaly add or update border/pcb edges
- action_plugin_test_undoredo.py: 4 examples to tests undo/redo features.