Note this post is based on the wrong installation path for the 4.0.7 release. See the later post for clarification.
TL;DR: create a scripting
directory in KiCads AppData, e.g. C:\Users\none\AppData\Roaming\kicad\scripting
and put your scripts there…
I managed to write a small script to generate some traces in the PCB layout, and now wanted to “package” that into an “action plugin”. Unfortunately, it does not get loaded into the “Tools > External Plugins…” menu.
Application: kicad
Version: (5.0.0-rc2-dev-466-g7b3dc9c28), release build
Libraries:
wxWidgets 3.0.3
libcurl/7.54.1 OpenSSL/1.0.2l zlib/1.2.11 libssh2/1.8.0 nghttp2/1.23.1 librtmp/2.3
Platform: Windows 8 (build 9200), 64-bit edition, 64 bit, Little endian, wxMSW
Build Info:
wxWidgets: 3.0.3 (wchar_t,wx containers,compatible with 2.8)
Boost: 1.60.0
Curl: 7.54.1
Compiler: GCC 7.1.0 with C++ ABI 1011
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
KICAD_SPICE=ON
Sources:
- http://docs.kicad.org/doxygen/md_Documentation_development_pcbnew-plugins.html
- HOWTO: Register a python plugin inside pcbnew Tools menu
- http://docs.kicad.org/master/en/pcbnew.html#_kicad_scripting_reference
- https://bugs.launchpad.net/kicad/+bugs?field.tag=windows
- https://git.launchpad.net/kicad/tree/scripting/kicadplugins.i#n166
According to kicadplugins.i
, for Windows the paths should be
<bundlepath>/
<bundlepath>/plugins/
[KICAD_PATH]/scripting/
[KICAD_PATH]/scripting/plugins/
<kicad_config_path>/scripting/
<kicad_config_path>/scripting/plugins/
I don’t know what bundlepath
or kicad_config_path
, but KICAD_PATH
is undefined on my system.
My install has several candidate directories, neither of which show an effect:
- C:\Program Files (x86)\KiCad\bin\scripting\plugins
- C:\Program Files (x86)\KiCad\share\kicad\scripting\plugins
There’s also
- C:\Users\none\AppData\Local\kicad
- C:\Users\none\AppData\Roaming\kicad
but these don’t seem to contain script-related stuff.
It does not matter whether it’s in scripting/ or plugins/.
BTW, the example script I’m using is
import pcbnew
class SimplePlugin(pcbnew.ActionPlugin):
def defaults(self):
self.name = "Plugin Name as shown in Pcbnew: Tools->External Plugins"
self.category = "A descriptive category name"
self.description = "A description of the plugin and what it does"
def Run(self):
# The entry function of the plugin that is executed on user action
print("Hello World")
SimplePlugin().register() # Instantiate and register to Pcbnew
So let’s try to help KiCAD a bit
set KICAD_PATH="C:\Program Files (x86)\KiCad\bin"
is not permanent, but adding it via the System settings (Advanced System Settings > Environment Variables, there’s probably a faster way to set it via CMD) did it:
>set KICAD_PATH
KICAD_PATH=C:\Program Files (x86)\KiCad\bin
and restarting KiCad finally resulted in the script being found.
But, since it’s in the program directory, it’s a pain to work with (any file change requires admin rights).
So let’s try to move the whole directory (CMD as administrator):
C:\Program Files (x86)\KiCad\bin>mklink /D "scripting\" "C:\Users\none\.kicad_plugins"
symbolic link created for scripting\ <<===>> C:\Users\none\.kicad_plugins
Note this directory is non-standard on Windows (I hope this does not cause any further confusion)!
So, while it does work with a bit of messing around, it does not work out of the box and so IMO it requires a bit of attention please.
Also what are the other two paths and how can one find out?
Should this be a bug report?