HOWTO: Register a python plugin inside pcbnew Tools menu

I look forward too. I am on a mac :slight_smile:

1 Like

I had also ask to @adamwolf for that point.

1 Like

I think I can automatically detect if there are some modifications or not. I’ll try this autodetection on a future patch.

1 Like

it seems that now the Action Plugin is delivered with the Nigtlies :smiley:

Application: kicad
Version: (2017-04-13 revision c4ea54227)-makepkg, release build
Libraries: wxWidgets 3.0.2
libcurl/7.52.1 OpenSSL/1.0.2k zlib/1.2.11 libssh2/1.8.0 nghttp2/1.19.0 librtmp/2.3
Platform: Windows 8 (build 9200), 64-bit edition, 64 bit, Little endian, wxMSW

  • Build Info -
    wxWidgets: 3.0.2 (wchar_t,wx containers,compatible with 2.8)
    Boost: 1.60.0
    Curl: 7.52.1
    KiCad - Compiler: GCC 6.3.0 with C++ ABI 1010
    Settings: USE_WX_GRAPHICS_CONTEXT=OFF
    USE_WX_OVERLAY=OFF
    KICAD_SCRIPTING=ON
    KICAD_SCRIPTING_MODULES=ON
    KICAD_SCRIPTING_WXPYTHON=ON
    KICAD_SCRIPTING_ACTION_MENU=ON
    BUILD_GITHUB_PLUGIN=ON
    KICAD_USE_OCE=ON

From now on, having a larger testing audience is much easier :wink:

I added an other Action Script to my repo:

Maurice

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
    • _init_.py A single file to register the plugin
    • date_plugin.py The plugin himself
    • any other files

Content of date_plugin.py

import pcbnew
import re
import datetime

class text_by_date( pcbnew.ActionPlugin ):
    def defaults( self ):
        self.name = "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"%datetime.date.today() )

Content of _init_.py

from date_plugin import *
text_by_date().register()
4 Likes

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?
Thx

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
Libraries:
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:
USE_WX_GRAPHICS_CONTEXT=OFF
USE_WX_OVERLAY=OFF
KICAD_SCRIPTING=ON
KICAD_SCRIPTING_MODULES=ON
KICAD_SCRIPTING_WXPYTHON=ON
KICAD_SCRIPTING_ACTION_MENU=ON
BUILD_GITHUB_PLUGIN=ON
KICAD_USE_OCE=ON

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