KiCad BOM Wizard
This is a KiCad plugin can be used to export custom BOM using configurable templates files. Built-in Examples include CSV, HTML & PDF.
This is a KiCad plugin can be used to export custom BOM using configurable templates files. Built-in Examples include CSV, HTML & PDF. KiCad_BOM_Wizard is writing in JavaScript and has been designed to integrate into KiCad’s BOM plugin manager.
The idea for KiCad_BOM_Wizard came from our need to generating BOM that are specific to our clients. for example, some of our clients require that their product have document traceability. With KiCad_BOM_Wizard, We simply made a template that the output file includes the document number, revision, and manufacture notes.
By default, KiCad_BOM_Wizard comes with two templates, one will generate a stand along HTML file and the other will generate a CSV file. They are both include to simplify the use of plugin and can be used as an example by those who want to make their own templates. The latter could be due to needing to have your own company or project logo.
Just in case you don’t know, KiCad’s plugin manager works by first generating an XML file that holds all of the project information include the list of parts you are using. After it generates this file, it will run a user define program with the XML file as an input parameter with any other user define parameters.
KiCad_BOM_Wizard works by scanning through all of the template files ( here’s the list ) and replacing any of the Short Codes with the data that is associated with it. It will then output all of the data into one file based on the order that it finds the short codes.
For example, if KiCad_BOM_Wizard finds the short code <!--TAG_TITLE--> in template.conf then it we replace it with the project title as set in the KiCad root document.
The plugin will group and sort all components together that have same parts value, the same starting designator reference prefix and the same fields value.
For example, if your project component list consist of;
then it would be grouped like this;
Ref | Qty | Value |
---|---|---|
C1 | 1 | 10pF |
R1 R3 | 2 | 10K |
R2 | 1 | 100K |
First you will need Node.js install and configure in you system. if you are using ubuntu then you can installing it by running the following commands.
If you are using windows or a mac you can follow this link to download node.js installer.
https://nodejs.org/en/download/
there have been reports that `node` wont run in KiCad BOM generator unless its full path has been specified.
If you have this issues, try replacing `node` with `PATH_TO_NODE/node` where PATH_TO_NODE is your system absolute path to node.
Here’s where it was first repoted: kiCad.info
The prefer method is to install KiCad_BOM_Wizard vai the NPM package manager. You just need to run the following command.
If you are using git, then you can run the flowing command to clone the project.
then run the install command inside the KiCad_BOM_Wizard directory
You will need to open an existing project schematic using KiCad Eeschema. For this example I am going to use KiCad complex_hearachy project example and setup KiCad_BOM_Wizard to generate the HTML and CSV BOM. I am also going to assume that you have the install node.js and proven that it works. And finally, I also going to assume that you have a copy of the KiCad_BOM_Wizard in your computer root directory.
In Eeschema, Click the BOM icon. this should bring up the following window.
Now click on the “Add Plugin” button. On the file explorer file, find and open “KiCad_BOM_Wizard.js”.
When prompt for the Plugin name, type in BOM_HTML and click OK.
So far the new plugin profile should look like this. Its not ready, we still need to add the extra parameters to make it work.
Under Command line: change it to the following.
SCRIPT_ROOT_DIR is the directory path to where your KiCad_BOM_Wizard.js is located, “%I” is replace by kicad with the xml file it generate and “%O” is also replaced by KiCad with the output directory and name.
To add the CSV profile repeat the HTML instructions but when prompt for the plugin name type BOM_CSV and change the Command Line: to the following.
SCRIPT_ROOT_DIR is the directory path to where your KiCad_BOM_Wizard.js is located, “%I” is replace by kicad with the xml file it generate and “%O” is also replaced by KiCad with the output directory and name.
To add the CSV profile repeat the HTML instructions but when prompt for the plugin name type in your own name and change the Command Line: to the following.
SCRIPT_ROOT_DIR is the directory path to where your KiCad_BOM_Wizard.js is located, YOUR_TEMPLATE is the directory path to your own template folder, MY_FILE_EXT is the file extension you want your output file to use, “%I” is replace by kicad with the xml file it generate and “%O” is also replaced by KiCad with the output directory and name.
We are assuming that you have already added the BOM_HTML profiles to KiCad plugin manager. We are also assuming that you have set the project sheet, date, company, revising and Comment 1 to 4.
Click the BOM icon in Eeschema. this should bring up the following window with the profile you have added.
Now select the BOM_HTML profile and click on the Generate button. When KiCad is done, it should show a Success message under the Plugin Info:.
If you go back to the KiCad Project Manager, you should now see the new HTML file that has been added to your project.
If you open the new html file you should get something like this.
KiCad_BOM_Wizard.js requires a specific set of files that allow it to successfully generate your BOM file. In this section, I will explain what files you need, how KiCad_BOM_Wizard uses them and which short code you can use in them.
The best way to start making your own template is by copying an existing one. The HTML and CSV templates that that come with KiCad_BOM_Wizard should be a good starting point. The following section should help in clarifying what each of the files and short codes do.
Here is a list of all the files that a template needs. If you are planning on using the file, simple leave its content blank.
File name | Description |
---|---|
template.conf | Main root |
headers.conf | The header configuration file is used to create the table headers. It should describe how a single header column should look like. |
group.conf | The group configuration file is used by KiCad_BOM_Wizard to generate a group of parts table data. |
row.conf | The row configuration file describes the row first four columns order and style. The columns are components designator, quantity, part value and fields. This is used by the group.conf. |
fields.conf | fields configuration file is used by KiCad_BOM_Wizard to generate the fields columns. If you want to generate a BOM without fields then you can simple leave this file blank. |
This are the lists of short codes that each of the files support.
Code | Description |
---|---|
<!--TITLE--> | inserts the root sheet title. |
<!--DATE--> | inserts the root sheet date. |
<!--DATE_GENERATED--> | inserts the date and time the Kicad net file was created |
<!--COMPANY--> | inserts the root sheet company name |
<!--REVISON--> | inserts the root sheet revision value |
<!--COMMENT_1--> | inserts the root sheet comment 1 |
<!--COMMENT_2--> | inserts the root sheet comment 2 |
<!--COMMENT_3--> | inserts the root sheet comment 3 |
<!--COMMENT_4--> | inserts the root sheet comment 4 |
<!--TOTAL_NUM_OF_PARTS--> | inserts the number of parts used in the design |
<!--TOTAL_NUM_OF_UNIQUE_PARTS--> | inserts the number of unique parts used in the design. Note, if two similar parts have different fields then it will be register as unique |
<!--CLASS_HEADER_TAG--> | inserts the table headers |
<!--BOM_TABLE--> | inserts the complete generated BOM table |
Code | Description |
---|---|
<!--HEADER_ROW--> | inserts the column title |
<!--HEADER_CLASS_REF_TAG--> | insert the tag for the part reference. HeadRefTag |
<!--HEADER_CLASS_QTY_TAG--> | insert the tag for the part qty. HeadQtyTag |
<!--HEADER_CLASS_VALUE_TAG--> | insert the tag for the part value. HeadValueTag |
Code | Description |
---|---|
<!--GROUP_ROW_DATA--> | inserts the group of parts row data |
<!--GROUP_CLASS_TAG--> | inserts the group class name. format "group_" + "part ref prefix" |
<!--GROUP_TITLE_TEXT--> | inserts the group title. the part ref prefix |
Code | Description |
---|---|
<!--ROW_PART_REF--> | inserts the list of parts reference designator |
<!--ROW_PART_QTY--> | inserts the number of parts grouped together |
<!--ROW_PART_VALUE--> | inserts the part value |
<!--ROW_PART_FIELDS--> | inserts the generator parts fields |
<!--ROW_CLASS_ODD_EVEN_TAG--> | returns RowEvenTag on even rows or RowOddTag for odds rows. |
<!--HEADER_CLASS_REF_TAG--> | insert the tag for the part reference. HeadRefTag |
<!--HEADER_CLASS_QTY_TAG--> | insert the tag for the part qty. HeadQtyTag |
<!--HEADER_CLASS_VALUE_TAG--> | insert the tag for the part value. HeadValueTag |
Code | Description |
---|---|
<!--FIELD_CLASS_TAG--> | inserts the fields class name |
<!--FIELD--> | inserts the field value |
Comments or questions are welcome.
Comment(39). Leave comment
After a little research I figured it out. The call to shell to node failed and the cause was an incomplete installation. Reinstalled node and all is well. My apologies for taking your time with this.
No problem. Its great to hear that its working for you.
– Ron
Not working for me I’m on Win 7 64 bit.
Getting this error:
Error: Cannot find module ‘C:\Users\rocko\AppData\Roaming\npm\node_modules\kicad_bom_wizard\KiCad_BOM_Wizard.js”E:\Kicad_4_Projects\Mixer\Small Mixer\Small Mixer.xml’
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.runMain (module.js:604:10)
at run (bootstrap_node.js:394:7)
at startup (bootstrap_node.js:149:9)
at bootstrap_node.js:509:3
I have re-installed npm to latest version still get the error.
Never mind I figured it out.
You need to put a space after ending quotation marks before starting a new set of quotation marks.
Doh!
No problem. Great to see that you have it working.
help with this error please.
Run command:
node “C:/Users/jacksil/AppData/Roaming/npm/node_modules/kicad_bom_wizard/KiCad_BOM_Wizard.js” “C:/Users/jacksil/Desktop/Duet-master/DuetWifiv1.01/DuetWifi.xml” “C:/Users/jacksil/Desktop/Duet-master/DuetWifiv1.01/DuetWifi.html”
Command error. Return code 1
Info messages:
KiCad_BOM_Wizard Rev: 0.0.8
reading KiCad XML file [ C:/Users/jacksil/Desktop/Duet-master/DuetWifiv1.01/DuetWifi.xml ]
Reading Template [ C:\Users\jacksil\AppData\Roaming\npm\node_modules\kicad_bom_wizard\Template\HTML ]
Generating BOM [ C:/Users/jacksil/Desktop/Duet-master/DuetWifiv1.01/DuetWifi.html ]
Error messages:
C:\Users\jacksil\AppData\Roaming\npm\node_modules\kicad_bom_wizard\KiCad_BOM_Wizard.js:318
value.field.forEach(function (value) {
^
TypeError: Cannot read property ‘forEach’ of undefined
at C:\Users\jacksil\AppData\Roaming\npm\node_modules\kicad_bom_wizard\KiCad_BOM_Wizard.js:318:20
at Array.forEach (native)
at C:\Users\jacksil\AppData\Roaming\npm\node_modules\kicad_bom_wizard\KiCad_BOM_Wizard.js:317:19
at Array.forEach (native)
at ExtractAndGenerateDataForThePart (C:\Users\jacksil\AppData\Roaming\npm\node_modules\kicad_bom_wizard\KiCad_BOM_Wizard.js:315:48)
at GenerateBOM (C:\Users\jacksil\AppData\Roaming\npm\node_modules\kicad_bom_wizard\KiCad_BOM_Wizard.js:398:18)
at Task (C:\Users\jacksil\AppData\Roaming\npm\node_modules\kicad_bom_wizard\KiCad_BOM_Wizard.js:632:7)
at C:\Users\jacksil\AppData\Roaming\npm\node_modules\kicad_bom_wizard\KiCad_BOM_Wizard.js:544:7
at tryToString (fs.js:449:3)
at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:436:12)
Hiya. Looks like there was an issue with the xml file. Could you try it using this test xml file to verify that your install is working.
https://github.com/HashDefineElectronics/KiCad_BOM_Wizard/blob/master/Example/example.xml
If this work, would you be able to share the xml file that you used with me? or something similar?
I encountered that error too. I found that it was caused by leaving empty (undefined) fields on components in the schematic. If you were using the “BOMs Away” script like I was, just be sure to not leave all custom fields such as MFR, MPN, SPR, SPN, etc. empty when filling in component info. Works fine for me now. Perhaps a safeguard against this sort of error can be put into the code in the future š
okay that worked…yeah i can send it to you
Hi,
I’m trying to generate my BOM but It just returning -1 error code and a error message. It think i did exactly as you teach.
My command line:
node “/usr/local/lib/node_modules/kicad_bom_wizard/KiCad_BOM_Wizard.js” “%I” “%O.html”
And the error message:
execvp(node, /usr/local/lib/node_modules/kicad_bom_wizard/KiCad_BOM_Wizard.js, /home/luigiesn/repos/tracker_circuit/Circuit/Tracker.xml, /home/luigiesn/repos/tracker_circuit/Circuit/Tracker.html) failed with error 2!
Problem solved!
I tried to perform “node” on terminal and it returned that the node package wasn’t installed. After installing, i was able to generate the BOM. Works perfectly!
Thanks!
Hi Luigi, Great to hear that you’ve got it working.
Hi I’m trying to install and got a return code 1 when i click on Generate…..however there doesn’t seem to be any errors
Run command:
node “home/tungsten/KiCad_BOM_Wizard/KiCad_BOM_Wizard.js””/home/tungsten/Documents/Devtank/JMAWireless/Hardware/ProdRETTester_KiCAD_Project/ProdRETTester.xml””/home/tungsten/Documents/Devtank/JMAWireless/Hardware/ProdRETTester_KiCAD_Project/ProdRETTester.html”
Command error. Return code 1
Please could you advise? I am running on Ubuntu.
Look forward to hearing from you.
Thanks
Tim
Hi Tim,
If you are trying to run the script in KiCAd, you will need to give the full path to the node.
In Ubuntu you should be able to get it via running the following.
which node
which I think will likely return the following:
/usr/bin/node
– Ron
Received an error message after trying to generate a BOM using the plug-in BOM_HTML as per your example. The error message is:
Run command:
Node “C:/Users/Greg/Documents/Electronic/Kicad/bom/KiCad_BOM_Wizard-master/KiCad_BOM_Wizard-master/KiCad_BOM_Wizard.js” “C:/Users/Greg/Documents/Electronic/Projects/High_Current_Distribution_Box/Kicad_REV1/High_Current_Distribution_Box.xml” “C:/Users/Greg/Documents/Electronic/Projects/High_Current_Distribution_Box/Kicad_REV1/High_Current_Distribution_Box.html”
Success
Error messages:
Error: dependencies are missing. Please run “npm install” in “C:\Users\Greg\Documents\Electronic\Kicad\bom\KiCad_BOM_Wizard-master\KiCad_BOM_Wizard-master”
I had done an install using your example above : npm install -g –production kicad_bom_wizard and there seem to be no errors that occur during this install process. When I try to repeat the install the last line displays “– [email protected]
Can you give me some hinds of what might to going wrong with my install?
I see the problem. The thing is that running
npm install -g āproduction kicad_bom_wizard
actually install a new copy of kicad_bom_wizard globally in your system so when you come to setup KiCad you will need to point to the global install instead of the one that download via Github in C:/Users/Greg/Documents/Electronic/Kicad/bom/KiCad_BOM_Wizard-master/KiCad_BOM_Wizard-master/KiCad_BOM_Wizard.js.So the error says Error: dependencies are missing. Please run ānpm installā in āC:\Users\Greg\Documents\Electronic\Kicad\bom\KiCad_BOM_Wizard-master\KiCad_BOM_Wizard-masterā which means that you need to run
npm install
inside C:/Users/Greg/Documents/Electronic/Kicad/bom/KiCad_BOM_Wizard-master/KiCad_BOM_Wizard-master/.This will ensure that you get all the dependency install in that directory.
– Ron
Hi, i also thought it might be worth sharing the shell errors i had when i followed the sudo npm install -g –production command. I got a lot of green successful npm pulls, but the following is a list of red errors.
npm ERR! TypeError: Cannot read property ‘latest’ of undefined
npm ERR! at next (/usr/share/npm/lib/cache.js:687:35)
npm ERR! at /usr/share/npm/lib/cache.js:675:5
npm ERR! at saved (/usr/share/npm/node_modules/npm-registry-client/lib/get.js:142:7)
npm ERR! at /usr/lib/nodejs/graceful-fs/polyfills.js:133:7
npm ERR! at Object.oncomplete (fs.js:107:15)
npm ERR! If you need help, you may report this log at:
npm ERR!
npm ERR! or email it to:
npm ERR!
npm ERR! System Linux 3.13.0-106-generic
npm ERR! command “/usr/bin/nodejs” “/usr/bin/npm” “install” “-g” “–production”
npm ERR! cwd /home/tungsten/KiCad_BOM_Wizard
npm ERR! node -v v0.10.25
npm ERR! npm -v 1.3.10
npm ERR! type non_object_property_load
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /home/tungsten/KiCad_BOM_Wizard/npm-debug.log
npm ERR! not ok code 0