HOWTO: Register a python plugin inside pcbnew Tools menu

I added an other Action Script to my repo:


1 Like

Thanks to @skuep, more detail about how to make a “clean” plugin:

While for single file plugins you can put that single file in the plugin directory, multiple files/complex plugin should be created with an other way. You can put all your files inside a sub-directory and put that sub-directory to the plugin directory.

An example:

  • ~/.kicad_plugin/ The main directory
  • MyPlugin/ Your plugin directory
    • A single file to register the plugin
    • The plugin himself
    • any other files

Content of

import pcbnew
import re
import datetime

class text_by_date( pcbnew.ActionPlugin ):
    def defaults( self ): = "Add date on PCB (onto a sub dir)"
        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" )

Content of

from date_plugin import *

I can not add this plugin even I have copied the script to those directories, how can I fix it ?
I have refreshed plugin and restart kicad, but external plugin is still not displayed…??

What version of KiCad, OS etc?
The plugin is for Nightly builds, not the “Stable” 4.0.x series

It is nightly build version. Os is Ubuntu 16.04.
I can t refresh plugin and the script has been copied to plugin directory.
How can I fix it?

It is kicad version 4.xx but I can not see it now. I m not on my computer.

4.xx is not Nightly. Your two last posts are contradicting each other.

Here’s the version I saw in Help --> About

Version : no-vcs-found-33048e7~59~ubuntu16.04.1,release build

Is that the right one ?

I still can not add new external plugin, do you have any ideas why ?

That is a very odd version name. Exactly which PPA are you using and when did you get it?

I used this
sudo add-apt-repository --yes ppa:js-reynaud/ppa-kicad
sudo apt update
sudo apt install kicad
Is there any other repositories?

That is the correct Nightly repository, rather than the 4.0.x Stable
As you did a manual install using apt, I am wondering when you grabbed this.

I grabbed on Saturday, do I need to reinstall it?

OK, I am more used to installing via Synaptic, which gives more meaningful names.
Did you also install kicad-library at the same time?
There is a 3rd package ,kicad-demo, but not essential

edit Do you have left overs from an older 4.0.x install, like kicad-common?

That’s the version :

Application: kicad
Version: no-vcs-found-e3c64f1~59~ubuntu16.04.1, release build
wxWidgets 3.0.2
libcurl/7.47.0 OpenSSL/1.0.2g zlib/1.2.8 libidn/1.32 librtmp/2.3
Platform: Linux 4.4.0-93-generic x86_64, 64 bit, Little endian, wxGTK
Build Info:
wxWidgets: 3.0.2 (wchar_t,wx containers,compatible with 2.8)
Boost: 1.58.0
Curl: 7.47.0
KiCad compiler: GCC 5.4.0 with C++ ABI 1009
Build settings:

I can not add external plugins, I have copied files to the plugin
directories, anything else missing here ?

I am thinking that apt might be missing dependencies or allowing you to have the wrong Python packages

The *.py script is already in /usr/share/kicad/scripting/plugins

but I still can not activate it, anyone knows why ?


Try installing the plugin in a hidden directory ~/.kicad_plugins.
It is the only location where I can get them to work

Edit: I always forget this bit

Application: kicad
Version: (2017-08-26 revision db3491f38)-master, release build
wxWidgets 3.0.2
Platform: Linux 4.10.0-33-generic x86_64, 64 bit, Little endian, wxGTK
Build Info:
wxWidgets: 3.0.2 (wchar_t,wx containers,compatible with 2.8)
Boost: 1.62.0
KiCad compiler: GCC 6.3.0 with C++ ABI 1010
Build settings:

I just had another quick look at this,
If you have cut and paste the code from the first ‘text_by_date’ example above to use as a script, then the code indentation below ‘def Run(self):’ is incorrect.

This will prevent it from showing in pcbnew External Plugins menu

1 Like

that one ?
def Run( self ):
pcb = pcbnew.GetBoard()
for draw in pcb.m_Drawings:

what should I fix with it ?