Tutorials on python scripting in pcbnew

iam using kifield library to export and import the schematic data to and fro from excel sheet.Iam having a problem where export command when triggered from python program is working, but import doesn’t.when i run these commands from command prompt both commands are working fine as expected.Iam using os module of python to trigger the commands.Any help would be highly appreciated.

  1. use os.path.dirname() to determine directory of the file
  2. you need spaces after -i and before -w arguments
  3. use subprocess module to run
1 Like

Thanks…That worked…but now iam creating one more plugin to add a data validation to the exported excel sheet. iam using pandas.The problem is when i import pandas in pcbnew console iam getting
ImportError: Missing required dependencies [‘numpy’, ‘pytz’, ‘dateutil’].

i downloaded a numpy zip and extracted to kicad/lib/python2.7/ sitepackages. then tried to import numpy.Iam getting this error message>
ImportError: Error importing numpy: you should not try to import numpy from
its source directory; please exit the numpy source tree, and relaunch
your python interpreter from there.

KiCad has moved on and is also using Python V3 now
Python V2 has finally been declared obsolete (that took 10 years too long).

To verify what Python version your KiCad uses, have a look at the version info, for example from Eeschema / Help / About KiCad / [ Show Version Info]. It should have a line like: “KICAD_SCRIPTING_PYTHON3=ON”

Installing Python libraries should not be done by downloading zip files.
Have you tried:

pip install numpy

There are still remnants of Python V2 lurking around. Sometimes you have to use “pip3” to install stuff for Python V3.x

1 Like

If you are not on windows then use pip to install needed packages. If you are on windows and use nightly kicad then use pip from kicad’s install directory. If you are on windows and use 5.1 kicad then it’s more trouble than it’s worth to install anything depending on numpy because that build is using a msys2/mingw toolchain and requires numpy compiled on that toolchain. I advise to switch to nightly.

Ok…will try in that way. One more query here…Can we add a dropdown for value field in kicad eeschema symbol fields table. i can see a browse button in footprint library. similar to that on value field i need a dropdown of predefined values. how to acheive this?

Short of modifying and rebuilding kicad code, you can’t.

I need to read values from Comment fields in a script. Something like GetTitle() but for Comment. I don’t know how to do it. Will you help me? Thanks.

TITLE_BLOCK has GetComment(index) method

Thank you very much for the advice, the command works. I just thought that in my case it would also load the content of the variable represented in the field. It just returns the name of the variable.

To expand text variables use

project = board.GetProject()
expandedvar = pcbnew.ExpandTextVars(var, project)