kicad-python-bom-scripts

2017-10-08  Robin Whittle rw@firstpr.com.au

In KiCad 4.0.7 there are several Python scripts for generating BOMs (Bills of Material).  They are not documented in the Eeschema manual.  There is some documentation in the file README-bom.txt the directory where the scripts are located:

C:\Program Files (x86)\KiCad\bin\scripting\plugins\

Windows does not normally have a Python interpreter, so I installed one as shown below.  By then, I decided that these supplied Python scripts were probably not as useful, or at least worth investing time in, as a fully developed and well documented system from the enigmatic Oliver AKA SchrodingersGat (2,579 contributions to github in the last year!!!):

https://github.com/SchrodingersGat/KiBoM

So I explored using this instead.

Please see the parent directory for other information about KiCad:  ../#bomw .

KiCad 4.0.7 also comes with a basic ungrouped BoM generation script, and one which groups components with the same value and footprint into single lines.  The latter has some bugs, which I fixed.  See:  ../kicad-data-structures/#group .

Contents

#int
01 - Installing a Python interpreter for Windows 7
#kibom
02 - Installing and using KiBom


#int

01 - Installing a Python interpreter for Windows 7

I have no particular interest in Python, but I known there are two different versions 2.x and 3.x which involve language differences. 

I installed a Python system from:

https://www.python.org/downloads/windows/

specifically the 3.6.3 2017-10-03 version, Windows x86-64 web-based installer.  This is a smaller single download than the full installer.  This was fairly straightforward. I enabled the tick box for Adding Python 3.6 to the PATH, so that the interpreter can be run from a command line just by "python", rather than by having to specify the full directory and file name of the python interpreter.



Now from a command window I can type "python", press enter and the interpreter runs and announces itself.



#kibom

02 - Installing and using KiBom

From https://github.com/SchrodingersGat/KiBoM I used the Clone or Download button to download a zip file, and unzipped the contents to:

D:\PCB\Kicad\python-scripts\KiBom\KiBoM-master\

It can produce the BoM file in .csv, .html or .xml formats.  To create a "plugin" for this, from Eeschema's BOM button on the top menu, I clicked the Add button, selected the main script of this package:

D:\PCB\Kicad\python-scripts\KiBom\KiBoM-master\KiBOM_CLI.py

accepted the name KiBOM_CLI for the name of the "plugin" and modified the command line which appeared, to add -KiBoM to the name of the output file.  The BoM file's name will start with the name of the schematic project, and be followed by "-KiBoM.csv".  My command line is:

python "D:\PCB\Kicad\python-scripts\KiBom\KiBoM-master\KiBOM_CLI.py" "%I" "%O-KiBoM"



The other two "plugins" are for generating one component per line BoMs and grouped BoMs, both with translation files which are run by xsltproc.exe as described in the pages linked to at the top of this one.

When I clicked the Generate button, a .CSV file was created, and KiBom reported several "Field conflicts" in the Plugin Info pane of the Bill of Material dialogue box.  These warnings concerned two or more components which it had grouped together (correctly) but for which one or more fields, had differing text for the value of these fields.  In the .CSV file, the reported value for that field's cell was the concatenation of these differing values.  Sometimes these fields will differ between grouped components, such as with my PCBVal field.  Still, I appreciate the program complaining about what might be faulty data. 

Here is what the BoM looks like when opened in Excel 2003:



KiBom is very well documented, easy to install and use, produces results which look good to me so far, and can have various aspects of its operation controlled by a per-project .ini file (or by any other such file as specified on the command line).  It can easily be made to generate a BoM for a specific number of boards and can handle multiple revisions of a design in which some components may or may not be mounted on the PCB. 

Since I don't yet have a completed PCB design, I will wait until I do before I explore its operation more.  For now: Salute!


Update history: