KiCAD on OS X - How to use python scripts? [solved]

Hello there,

I am using Mac OS X and a KiCAD downloaded from here http://downloads.kicad.org/osx

As these KiCAD versions are compiled from the latest sources, I anticipating it supports scripting. The question is now how to use these neat little scripts? I am not interested in an API for writing my own scripts. What I want to know is how to install scripts from others so that I can use them - and when installed how to execute them.

Where do I need to save the scripts? I tried it in…

~/Library/Application support/kicad/plugin/ 

…but nothing changed in KiCAD.

This is the script I want to run: https://github.com/svofski/kicad-teardrops

I googled but simply was not able to find anything out there. I really Hope anyone here can help me!

Thanks!
Airic

Nevermind. It seems that scripting is not active for the Mac version that I downloaded.

As a reference - this is how it works under windows:

Save your python script in the installation folder of your KiCAD under:

...\kicad\bin\scripting\plugins

Then start pcbnew and in the menu select Tools --> Scripting Console
A new window will open.
To run your script enter:

import scriptName

This would be valid if your script file would be named scriptName.py

This is what I was looking for - Thank you!

There are some problems with the Mac version though. I needed to reassign a KiCAD shortcut (“o” for adding footprints) because the main window behind the scripting window seems to still catch all key presses.

This means that typing “import” becomes impossible if the “o” lands somewhere else. There are other shortcuts (like “x” for starting a track) that might be a problem here. This is a bug that basically draws this feature useless for the Mac version. I guess I use my Windows KiCAD just for adding teardrops to the vias when a board is ready.

Just a quick note for others here as I was tripped up by it - you need to restart pcbnew after creating the scripting/plugins/ subdirectories of KiCad/bin/, otherwise your scripts won’t be found. After that point you don’t have to restart pcbnew when changing/creating your scripts however.

A small work around is to resign/remove the actions for “o” and “x” by navigating to Preferences >>Hotkeys >> Edit hotkeys.

Where in a Mac file system should plugins be stored? I tried ~/Library/Application support/kicad/bin/scripting/plugins, but I get an import error saying “ImportError: No module named script.py” when I try the import command.

Which part of that path was already there/generated by KiCAD?
Is that where your KiCAD executable(s) reside or just a temp/cache/etc. folder somewhere else in your system?
Sorry, I’m a windows guy, so can’t be of much help.

No worries, windows guy. This is what I see. Since I can get a console, I am fairly certain my version is compiled with scripting enabled.

None of that path was created by KiCAD. I created a folder called bin, and all others after it within the KiCAD application support folder. However, I determined that the current directory in the console window is /Application/KiCAD, so I’ve made some progress. I still have yet to successfully run a script though.

so your real KiCAD executables are in …/application/… and not in …/library/application support/ … ?
Do you have the bin/script/plugin structure re-created over in that other folder yet for test?

Have a read over here please and see if that get’s you something tangible:

Richard, are you putting this folder (\bin\scripting…) in the KiCad folder containing the apps, or the one in the app support folder?

Currently, there is no real good support for user plugins due to how system/user paths are handled in the code.
Paths are hardcoded to be

  • In the application bundle for delivered content: …/kicad.app/Contents/SharedSupport/scripting/plugins
  • Via environment variable: $(KICAD_PATH)/scripting/plugins

Footprint wizard python plugins delivered with the application bundle are known to work since 6241.
The path via $(KICAD_PATH) was always there, but I never did try it…

Hello,

I’m desperatly trying to get the plugins work with osx. Does someone know what version of kicad should i use (currently latest nightly build) , how to activate plugins and what path should they be placed in ?
thanks for your help

If you are using your own scripts, you can call them from wherever you like with an execfile("/path/to/file.py") from the Kicad python terminal prompt. If you do an

import sys 
print(sys.path) 

you will get some useful info about the python setup.

If you are taking about plugins, on macOS you should place these in ~/Library/Preferences/kicad/scripting . Some, like InteractiveHTMLBOM, should sit in their own folder, others should be free in the scripting folder.

True for 5.1.2 - I can’t recall if this was different in previous versions.

Since this is such an old thread and there may have been chsnges, it might be best to make a new thread unless this closes your issue and nobody has any further comments.

1 Like

thanks a lot for your help.
I’m running 5.1.0 nightly build (i thought it was the latest version i could get on mac) and there are no scripts in ~/Library/Preferences/kicad/scripting:

vallettea@retina:~$ cd ~/Library/Preferences/kicad/
vallettea@retina:~/L/P/kicad$ ls
3d                        eeschema                  pcbnew
PyShell_pcbnew.cfg        fp-lib-table              sym-lib-table
PyShell_pcbnew_startup.py kicad
cvpcb                     kicad_common

For the moment i’m using the exec method but it would be great if i could use my own python in a real terminal and even with iphython…