I’m switching from KiCad 3 to KiCad 4.
While version 3 offered a simple, quite un-customizable, CSV generated BOM, version 4 now only offers a raw XML export.
As KiCad website says:
BOM generation is extensible via Python scripts or XSLT, which allows many configurable formats.
“many configurable formats” This is great! It’s even possible to use any program or language other than Python and XSLT to translate the XML in whatever format pleases you.
The downside is, it requires additional steps before you can actually generate a BOM. It seems a bit complicated but it’s not. Read below.
We need to use a third party BOM Generator.
Most of them offer CSV formatted outputs (Joost’s KiCad BOM generation).
“KiCad BOM Wizard” from hashdefineelectronics.com can also produce HTML output. Very nice.
KiCad installation provides some demo XSLT BOM generators. On my Ubuntu 16.04, they are located here:
There’s much more on the web. I’ve made my own BOM generator, based on ruby.
How to use them
KiCad website has a short Youtube video.
In Eeschema, click on menu “Tools > Generate Bill Of Materials” or click on the toolbar button “BOM”. A new “Bill of Material” window shows up. “Plugins” list should be empty if you haven’t previously added some generators. We’ll do now.
Click on “Add plugin”. A file search dialog invites you to choose your plugin. Browse up to it, click “open”, enter the name you want, and we’re set.
Now, depending on the kind of plugin you chose, we need to customize things a bit more.
XSLT and Python scripts seems to be somewhat recognized by KiCad and some essential parameters are automatically added. If not, here they are:
First, we need to specify the processor (python, xsltproc, perl, ruby…).
"%O" parameters. “%I” is replaced by the name of the XML file exported by Eeschema, “%O” by the corresponding name of the generated file.
For example, if your project’s name is “MyProject.pro”, “%I” will be replaced by “MyProject.xml” and “%O” by “MyProject”. Note the absence of extension. This lets you generate whatever format you want.
python "/home/david/elec/scripts/kicad_bom_perso.py" "%I" "%O.csv"
node "/home/david/elec/scripts/KiCad_BOM_Wizard-master/KiCad_BOM_Wizard.js" "%I" "%O.html"
Use the BOM
Once the CSV file is generated, you can import it in your favorite Spreadsheet or directly import it in Mouser’s or Farnell’s shopping cart.
Joost’s HTML export is useful for creating a nice on-line documentation or create click-able links to your provider’s website.
If you encounter a “Command error. Return code -1” followed by “failed with error 2!” then you might need to install xsltproc, Python and any required package:
sudo apt-get install python
sudo apt-get install xsltproc