KiCad BOM Wizard Plugin with customisable output (Can make HTML and CSV BOM)


#42

I took the easy way out… opened up the XML-file in Excel and sanitised it there :slight_smile:


#43

Hi Ron,
I’m new kid in the block when it come to using Ki_Cad, I just finished the project that I’m working on and I found out that creating the BOM is not easy. I might be guilty of creating some of the issue that I’m facing since each component has the following fields:

Reference
Value
Footprint
Datasheet
Manufacturer
Part Number
Voltage
Current
Power (Watts)
Tolerance
Operating Temperature

I’m using Window operating system. I followed the instruction you posted on Jan 16, i watched the 24 min video and i did exactly what you instructed

and I’m getting the following error:

Can’t open file C:\ProgramFiles|KiCad\share\KiCad\demos\complex_hierarchy.xml (error 0: the operation completed successfully.)

I’m kind of stuck, anything you can do to help me generate the BOM will be greatly appreciated.
Also I wanted to thank you for the fine work you have done

Best regards

Saad (ST2)


#44

Hi Ron,
I got a better result after few attempts but I’m still getting the error, below is the BOM error report, hope this can shed light on this issue

Run command:
node “C:/My_Circuit_KICAD/KiCad_BOM_Wizard-master/KiCad_BOM_Wizard.js” “C:/My_Circuit_KICAD/GettingToBlinky/GTB.xml” “C:/My_Circuit_KICAD/GettingToBlinky/GTB.csv” “C:/My_Circuit_KICAD/KiCad_BOM_Wizard-master/Template/CSV”

Command error. Return code 1

Info messages:
KiCad_BOM_Wizard Rev: 0.0.8

Error messages:
module.js:471
throw err;
^

Error: Cannot find module ‘xml2js’
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at ReadXmlFile (C:\My_Circuit_KICAD\KiCad_BOM_Wizard-master\KiCad_BOM_Wizard.js:433:16)
at Task (C:\My_Circuit_KICAD\KiCad_BOM_Wizard-master\KiCad_BOM_Wizard.js:608:7)
at Object. (C:\My_Circuit_KICAD\KiCad_BOM_Wizard-master\KiCad_BOM_Wizard.js:132:1)
at Module._compile (module.js:570:32)
at Object.Module._extensions…js (module.js:579:10)
at Module.load (module.js:487:32)


#45

I"m stuck and trying to figure out what did you mean by “After installing the node trough npm:”

I found a file under Roaming named npm but its empty ,

Any input you can provide will be greatly appreciated

Best regards

Saad (ST2)


#46

My fault, I was not correctly describing the process… you should install Node. npm comes together too. I used this as a guide:
https://docs.npmjs.com/getting-started/installing-node
but only for the part of installation of npm and Node.

After that you open the npm and install from there the bom wisard: C:\Users\pok>npm install -g --production kicad_bom_wizard
using this guide:
https://docs.npmjs.com/getting-started/installing-npm-packages-globally

And than you use the path where npm installed the bom wizard to make your command line in KiCad like described by the author of the wizard.

That is what I can supply as information, sorry! It was some time ago and I don’t remember very well the exact order, because I’am by no means specialist in this matter.

It will be very helpful if somebody more fluent in this aspect can construct some meaningful installation scenario for Windows 10, including the initial installation of Node and npm.

Best Regards!


#47

Of course you must have already downloaded the installation package for the wizard somewhere, so that you can install it from there to some particular location on the disc, using the npm. Than the path of this destination must be used to compose your command line, like described before.


#48

POK< many thank s for your help,I 'm going to try again, this way above my pay rate, will try again


#49

For some reason I can’t install NPM (maybe) i tried to verify the version but it gave me error [ i ran node , i typed npm -v and i got an error message saying reference error npm is not defined


#50

Pok, Many thanks , got it to work , Very happy :slight_smile::sunglasses:


#51

@ST2 great to hear that you have it working. Sorry for the lack of reply unfortunately this is contract season for me and unfortunately my side projects usually are the first to go :frowning:

@Pok thank you

  • Ron

#52

Thank you Ron, I really appreciate you sending this email to me and many
many thanks for all the fine and useful work you’ve done for this community

Best regards

Saad Thabit
Founder and Principal Engineer
DRF Engineering Services LLC.
860 Worcester Road| Suite 101
Framingham, MA.
01702508.314.0845thabit@drfengineeringservices.comwww.drfengineeringservices.com

https://www.facebook.com/DRF-Engineering-Services-1549921131971008/
https://www.linkedin.com/in/saad-thabit-481071a


#53

Not sure you meant to send this message to the forum?


#54

Hi All,

I’ve finished implement some new feature to the plugin and I was wondering if anyone fancy trying it out before the final merger for release?

Here’s what changed on 0.0.9 (peding release)

Added

  • Added support for options files. for now on any new features will be implemented and made configurble via the options file. this will also make it eaiser to have a standard setup between projects.
  • Added PDF support. the PDF generator uses html templates to create the PDF file.
  • Added HTML_PDF template for use with the PDF generator
  • Added BOM sort and the related configuarable settings. You can now sort ASC/DEC by ref, value and footprint.

Fixed

  • Fixed the issue where file names with space would break class tags
  • Fixed the missing filed header class tags

Here’s what the new PDF template looks like

and here the PDF example if anyone want to have a closer look.
kicad_bom_wizard PDF output hash Define electronics.pdf (138.3 KB)

Getting the dev code

To get access to 0.0.9 you will need to git clone the project and then checkout the develop branch.

git clone https://github.com/HashDefineElectronics/KiCad_BOM_Wizard.git
cd ./KiCad_BOM_Wizard
git checkout develop

then you will need to run the install

npm install -g ./

Using it

At this point, you should be able to use the plugin the same way as you did previously except that you can now pass it a config instead of a series of commands parameters.

you can find an example of the config file on the project root directory under Example/options.json.

Using the new config file, all you need to do is now call kicad_bom_wizard and give it the location of your config file.

kicad_bom_wizard CONFIG_PATH/options.json

where CONFIG_PATH is the directory to the options.json.

configuration file example

Here what the configuration file looks like. All path can be relative to the config file, relative your current working directory, relative to kicad_bom_wizard or absolute .

{
  "version" : 2,
  "outputType" : "pdf",
  "templatePath" : "HTML_PDF",
  "outputPath" : "../Test/.tmp/",
  "outputName" : "output.pdf",
  "input": "example.xml",
  "pdfOptions": {
    "pageSize": "A3",
    "printBackground" : true,
    "landscape": true,
    "marginsType" : "0"
  },
  "sort" : {"by": "ref", "ascending": true}
}
  • outputType needs to be either pdf or file. where file is that you intent to make you own text file. for example csv or html.

  • templatePath this is the path to your template file. This can either be CSV, HTML, HTML_PDF or a path to your own.

  • outputPath this is where you intend to save your output file

  • outputName this the name that you want to the output file to be called.

  • input this the path and name of your project xml file.

  • pdfOptions this are some of the options for configuring the PDF output if you are using PDF

  • sort by this sets the BOM component grouped sort order. You can set it too ref, value, value_num and footprint. where value_num means that the value filed is to be treated as numbers.

– Ron


#55

Hi ! I’m getting the following error when attempting to use the BOM Wizard:

Command error. Return code 8

Info messages:
KiCad_BOM_Wizard Rev: 0.0.8

Error messages:

module.js:340
throw err;
^
Error: Cannot find module ‘xml2js’
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at ReadXmlFile (/home/grpace/Electronics/KiCad/BOM Wizard/KiCad_BOM_Wizard.js:433:16)
at Task (/home/grpace/Electronics/KiCad/BOM Wizard/KiCad_BOM_Wizard.js:608:7)
at Object. (/home/grpace/Electronics/KiCad/BOM Wizard/KiCad_BOM_Wizard.js:132:1)
at Module._compile (module.js:456:26)
at Object.Module._extensions…js (module.js:474:10)
at Module.load (module.js:356:32)

Running Ubuntu 14.04
Is a re-boot necessary after installing nodejs ?

Greg


#56

Got this plugin “somewhat” working, and here’s my thoughts / findings:

Issues:


Having to install nodejs and npm just to get the BOM Wizard package to begin with.
Just wanted to test the plugin… Additional required installs/dependencies should NOT be necessary.

Once that’s installed, the BOM Wizard instructions state that from Eeschema, click the BOM button, then:

… click on the “Add Plugin” button. On the file explorer file, find and open “KiCad_BOM_Wizard.js”

It’s not stated that, under Linux, this location ends up being:
/usr/local/bin/kicad_bom_wizard

No… Wait… That’s just a symbolic link (symlink) pointing to somewhere else…
Now one has to look at the symlink’s properties to determine exactly where it points to. This ends up being:
/usr/local/lib/node_modules/kicad_bom_wizard/KiCad_BOM_Wizard.js

WHY is this plugin spread out like this ??


Then the BOM Wizard instructions further state:

… Its not ready, we still need to add the extra parameters to make it work… Under Command line: change it to the following…
node "SCRIPT_ROOT_DIR/KiCad_BOM_Wizard.js" "%I" "%O.html"

This ends up being (without the line-break shown here):
node "/usr/local/lib/node_modules/kicad_bom_wizard/KiCad_BOM_Wizard.js" "%I" "%O.html".

Nope… That fails with errors.
Have to remove the quotation marks around the path name to KiCad_BOM_Wizard.js

Nope… That fails with errors.
It’s not “node”… It’s “node.js”.
Correct that and… FINALLY ! GETTING SOME OUTPUT !


Now… Let’s try customizing the HTML template a bit…
It’s folder is located at:
/usr/local/lib/node_modules/kicad_bom_wizard/Template/HTML/

Guess what ??? THAT folder is owned by “root” !
Cannot customize it without forcing root privileges… NOT GOOD good on Linux systems.

So…
Open a terminal, navigate to that Template folder and use sudo to change it’s owner to yourself so it can be edited.
Nope… Still can’t edit it… It’s also READ-ONLY !!

GREAT !! Now, what ??
You either have a choice of changing the templates from read-only where they sit, or loading them in a text editor and saving them to your home folder.

Reading the instructions further:

…change the Command Line: to the following.
node “SCRIPT_ROOT_DIR/KiCad_BOM_Wizard.js” “%I” “%O.MY_FILE_EXT” “YOUR_TEMPLATE”
YOUR_TEMPLATE is the directory path to your own template folder…

Well… That’s basically telling us we need template folders in two separate locations !! That really spreads this thing out even more !!

Then, once all that’s done, in order to use/place your own logo, you gotta visit


to get your logo image converted into a format suitable to place in the custom HTML’s style sheet section and save the template. Then, at least for me, the logo image fails to render.


Conclusion:

The installation of this plugin and getting it to somewhat work on Linux/Ubuntu is absolutely horrendous ! There is simply NO REASON it should be this way and one has to go through all these steps.

I truly hope the author addresses these issues before the next release.

Greg


#57

Hi Greg, sorry to hear you were having issues with the setup process.

Hi ! I’m getting the following error when attempting to use the BOM Wizard:

Command error. Return code 8

Info messages:
KiCad_BOM_Wizard Rev: 0.0.8

Error messages:

module.js:340
throw err;
^
Error: Cannot find module ‘xml2js’
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at ReadXmlFile (/home/grpace/Electronics/KiCad/BOM Wizard/KiCad_BOM_Wizard.js:433:16)
at Task (/home/grpace/Electronics/KiCad/BOM Wizard/KiCad_BOM_Wizard.js:608:7)
at Object. (/home/grpace/Electronics/KiCad/BOM Wizard/KiCad_BOM_Wizard.js:132:1)
at Module._compile (module.js:456:26)
at Object.Module._extensions…js (module.js:474:10)
at Module.load (module.js:356:32)

Running Ubuntu 14.04
Is a re-boot necessary after installing nodejs ?

Did you install it via npm or via git clone? If by git clone then you need to make sure that you run npm install -g --production kicad_bom_wizard inside of the plugin directory. This will ensure that you have all the dependencies.

/usr/local/lib/node_modules/kicad_bom_wizard/KiCad_BOM_Wizard.js
WHY is this plugin spread out like this ??

For the issue that you had with the location and root permission for the plugin directory are all down to how NPM is setup. In linux, by default NPM is configure to use the root directories. This is something that NPM know is an issue to some of their user and have addressed by publishing this instruction on fixing it “03 - Fixing npm permissions”.

Nope… That fails with errors.
It’s not “node”… It’s “node.js”.
Correct that and… FINALLY ! GETTING SOME OUTPUT !

I’m guessing that you’ve installed nodejs via Ubuntu package (sudo apt-get install nodejs). Unfortunately in ubuntu, the module node is taken up by another program and so when you install nodejs it has to to use nodejs. :disappointed:

This could be fixed if you manually download and install nodejs. This would also ensure that you have the latest version of nodejs and npm.

Now… Let’s try customizing the HTML template a bit…
It’s folder is located at:
/usr/local/lib/node_modules/kicad_bom_wizard/Template/HTML/

Even if you didn’t have the root permission issue here, I would still advice not to make changes to the templates that comes with the plugin. If you do then you are likely to loss your changes if you ever decide to up the plugin. Specially now that I’m in the process of introduction some new features. Ideally, you need to code the template and make your changes there.

to get your logo image converted into a format suitable to place in the custom HTML’s style sheet section and save the template. Then, at least for me, the logo image fails to render.
Would you be able to share your template so that I can see where it failed?

Conclusion:

The installation of this plugin and getting it to somewhat work on Linux/Ubuntu is absolutely horrendous ! There is simply NO REASON it should be this way and one has to go through all these steps.

I truly hope the author addresses these issues before the next release.

Unfortunately, some of the issues that you mentioned will be hard to remove without KiCad having better support nodejs. For example, Getting KiCad to recognise that you are running a nodejs script in the KiCad BOM tool rather than you have to manually insert node (or nodejs). That said, I’ve been playing with the idea of intergrating this plugin (or at least the functionality) into kicad. Its only something that I would do if the developer are happy for me to do it and enough people want it.

Not sure if you be interested but I’ve released 0.0.9 for testing. It has a new way to configure the pluiging and support for PDF creating. Hopefully it’ll remove some of issues that you’ve found.

I do wonder if it would be better if I add UI to the plugin so that it can run without having to worry user needing to use a terminal. :slight_smile:

– Ron


#58

Hi, Ron.
I’ll (maybe try) to better explain my thoughts.

I use grsync to backup my system. I have two profiles set up in it… One for the main operating system and another for only my /home directory. This ‘separation of tasks’ makes backups much faster, as only what has changed since the initial or last backup gets updated. The way your plugin is structured (by needing external dependencies) breaks this separation.

I have looked at the npm link you posted, and will likely try Option 2 to see if that will help bring this ‘separation of tasks’ back in sync. I believe I’ve seen a post by you here that node/nodejs was the way you were most comfortable with developing software… There’s nothing wrong with that. However, it may be advantageous for new users of your plugin if you could better explain some of the caveats one could run in to and the available options for addressing them.

I installed it with npm. The thing is, I may never need or use nodejs and npm for anything else.

This was one of the major issues. Your documentation doesn’t define exactly where that plugin directory is… One has to hunt for it. Fortunately, Linux has the locate command that helps some. As stated, a plugin for a particular software package shouldn’t have to need external dependencies to work. From an overall software design standpoint, I feel the packaging method of the plugin isn’t very eloquent.

That happening may very well be unlikely, as it appears most use Python for plugins and it is quite well supported. I somewhat doubt that nodejs support will be made widely available for only a few (but I could be wrong on that).

That would absolutely be an improvement. And as stated, updating your documentation to include pitfalls and viable work-arounds for a new user would help immensely… I was basically “going at it blind” while trying to get the plugin running.

I hope I have explained this well enough.
Have a good day !
Greg


#59

I use grsync1 to backup my system. I have two profiles set up in it… One for the main operating system and another for only my /home directory. This ‘separation of tasks’ makes backups much faster, as only what has changed since the initial or last backup gets updated. The way your plugin is structured (by needing external dependencies) breaks this separation.

I understand. I have a similar need with my backup. You could always install the plugin without the -g command. This will ensure that the install is kept in the folder that you placed the plugin. The down side is that you won’t be able to access KiCad_BOM_Wizard globally because it won’t be added to your system path (its not like kicad can access it anyway :D)
For example:

cd ~/
git clone https://github.com/HashDefineElectronics/KiCad_BOM_Wizard.git
cd KiCad_BOM_Wizard/
npm install --production .

Here how to use it:

NODE_DIRECTORY/node ~/kicad_bom_wizard "%I" "%O.csv" "CSV"

I think I’ll add this to the use instruction just in case.

I have looked at the npm link you posted, and will likely try Option 2 to see if that will help bring this ‘separation of tasks’ back in sync. I believe I’ve seen a post by you here that node/nodejs was the way you were most comfortable with developing software… There’s nothing wrong with that. However, it may be advantageous for new users of your plugin if you could better explain some of the caveats one could run in to and the available options for addressing them.

I was hoping that this thread would help with that due to the limited time I have for side projects. That said, you are right and it makes since to add a dedicated section for common issues users might find. :smiley:

This was one of the major issues. Your documentation doesn’t define exactly where that plugin directory is… One has to hunt for it. Fortunately, Linux has the locate command that helps some. As stated, a plugin for a particular software package shouldn’t have to need external dependencies to work. From an overall software design standpoint, I feel the packaging method of the plugin isn’t very eloquent.

Fair enough ;D

That happening may very well be unlikely, as it appears most use Python for plugins and it is quite well supported. I somewhat doubt that nodejs support will be made widely available for only a few (but I could be wrong on that).

Sadly you might be right. That said, I’ve been wondering if its worth porting the code over to python for this very reason but then again I’m not sure if the efforts would be worth it. it might be easier and possibly quicker if I simply added the necessary changes to KiCad and send a patch over to the Devs :thinking:

– Ron


#60

So I’m have trouble with mine. I’m using windows 10 and KiCad 4.0.4. I’ve installed nodejs via the windows installer and KiCad BOM Wizard.

When I generate the code using node “C:\KiCad_BOM_Wizard-master\KiCad_BOM_Wizard.js” “%I” “%O.html” I get this error:

Run command:
node “C:/KiCad_BOM_Wizard-master/KiCad_BOM_Wizard.js” “C:/Users/User/Documents/1UInergy/KiCad/prototype2/prototype2.xml” “C:/Users/User/Documents/1UInergy/KiCad/prototype2/prototype2.html”

Command error. Return code 1

Info messages:
KiCad_BOM_Wizard Rev: 0.0.8

Error messages:
module.js:471
throw err;
^

Error: Cannot find module ‘xml2js’
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at ReadXmlFile (C:\KiCad_BOM_Wizard-master\KiCad_BOM_Wizard.js:432:16)
at Task (C:\KiCad_BOM_Wizard-master\KiCad_BOM_Wizard.js:607:7)
at Object. (C:\KiCad_BOM_Wizard-master\KiCad_BOM_Wizard.js:131:1)
at Module._compile (module.js:570:32)
at Object.Module._extensions…js (module.js:579:10)
at Module.load (module.js:487:32)

This error looks similar to a few other users here. I tried putting the full path for node in but that doesn’t work. The windows installer put it in C:/ProgramData/Microsoft/Windows/Start Menu/Programs/Node.js so that’s what I put. With and without the .js

What do I try next?

Thanks!


#61

Try using nodejs instead of node.
Remove any quotation marks around the node command.
Only use quotation marks around %I and %O variables.
See my post above… I tried to cover issues I had.

Greg