So I am running BZR 6086 under Windows 7. I have a working scripting console which I can type commands into and test things out. However, I can’t seem to figure out where to add my own scripts so that I can import them into the console’s interpreter.
For example, I have a KiCad project (.pro) with a PCBNEW (.kicad_pcb) file in my home directory. I open the KiCad project viewer and then from there open the PCBNEW file. Here is the python load path right after the scripting console is opened:
Welcome To PyCrust 0.9.8 - KiCAD Python Shell
Python 2.7.10 (default, Jul 8 2015, 15:10:39)
[GCC 5.1.0] on win32
Type "help", "copyright", "credits" or "license" for more information.
import sys
sys.path
['C:\\Program Files\\KiCad\\lib\\python27.zip', 'C:\\Program Files\\KiCad\\lib\\python2.7', 'C:\\Program Files\\KiCad\\lib\\python2.7\\plat-win32', 'C:\\Program Files\\KiCad\\lib\\python2.7\\lib-tk', 'C:\\Program Files\\KiCad\\lib\\python2.7\\lib-old', 'C:\\Program Files\\KiCad\\lib\\python2.7\\lib-dynload', 'C:\\building\\msys32\\mingw64', 'C:\\Program Files\\KiCad\\lib\\python2.7\\site-packages', 'C:\\Program Files\\KiCad\\lib\\python2.7\\site-packages\\wx-3.0-msw', '.']
import os
os.getcwd()
'C:\\Program Files\\KiCad'
As you can see, none of the provided directories are in user-accessible areas. Even the current directory is set oddly in that I would expect it to be the directory of the PCBNEW (*.kicad_pcb) file. Thus in order to use my own scripts, I am forced to manually append a user directory to the python load path every time I want to use the scripting console.
Does anyone have any advice on how to improve this situation short of going into the source code and making my own version of PCBNEW?
FYI, since the scripting console can not be extended with my own scripts in this state AFAIK, I’ve mainly been executing my PCBNEW scripts outside of the scripting console via:
“C:/Program Files/KiCad/bin/python.exe” my_script.py
The script (my_script.py) will have a structure like this:
import pcbnew
board = pcbnew.LoadBoard("test.kicad_pcb")
# Do some operations on the board.
board.Save(board.GetFileName())
And then closing PCBNEW and reopening to see the effect. However, this is somewhat awkward, especially considering there is this nice scripting console that is going unused.