KiCad BOM plugins (was KiCad BOM in Markdown)

Just copy and paste what into what???

where does all that crazy text go?

where is the .py or whatever file?

im a noob… halp…

i just tried to generate a BOM from KiCAD and it was absolutely atrocious… if any of you have tried to do the same… you know as well as I do that i may as well just do it cell by cell lmao.

please. baby steps like im stupid… lol

and whats a markdown file… ?

3 Likes

I’ll wait for @analogoutput to explain, since this seems it uses a separate python environment maybe KiCad has it’s own environment?

2 Likes

I wrote it up as a blog post:


Let me know what I left out or didn’t make clear.
8 Likes

No you’re not

No you’re not

6 Likes

Thanks @analogoutput! This looks nifty! Do you know if the windows KiCad bundles with a python environment? Windows (unfortunately) does not have a system python. Any idea if the linux version just uses the sytem level python? I didnt see you mentioning installing any modules etc, and i see some imports in the code that arnt stock.

image

Of course, if these are “pre-compiled” python plugins thats a horse of a different color.

2 Likes

As it says in the blog post, you have to put kicad_netlist_reader.py into the same directory as the BOM plugin.

I just assumed KiCad uses the system Python but maybe not. No idea about Windows. But the KiCad-supplied BOM scripts are Python, or at least some are, and if the same scripts are used in the Windows version then either it packages its own Python environment or it would require one be installed, I suppose.

2 Likes

I just know windows is going to be at fault. If this is pre-compiled, it would bundle all of the dependencies necessary. Alls im saying is if we got some windows users here (probably), they may have more trouble than what is covered in your blog post.

We will burn that bridge when we get there.

3 Likes

This is not a problem I have encountered using online EDA with a chromebook or android device.
Longing for the day my windows only software will run reliably on Linux so my last windows machine will die and I’ll get an average of 28 working hours a year back not having to “please wait while we update” (it’s close but not there yet)

3 Likes

There’s this

4 Likes

OK, baby steps. If you are generating a BOM from the schematic, there is a menu item to generate a BOM. It should have some selections in it like this. image After you select “Generate” it will make a new output file. For the highlighted selection in the image, it will generate a new file that has the same name as your project but it will not have an extension. Windows will not know what to do with it. Rename the file and add “.csv” to the end of the file name, be sure to include the “.”, then it will open in excel with all the columns correctly sorted.

3 Likes

You can and should modify the command line at the bottom to include the extension. That change will persist, so you won’t have to do it every time.

5 Likes

The change is persistent? Oh, thank you! I really thought it was not. This changes everything!

So baby steps. In the image where it says command line, for windows it should have
python “C:\Program Files\KiCad\bin\scripting\plugins/bom_csv_grouped_by_value_with_fp.py” “%I” “%O”
add .csv to the output like this:
python “C:\Program Files\KiCad\bin\scripting\plugins/bom_csv_grouped_by_value_with_fp.py” “%I” “%O.csv”
You can also add .html to the ones that say “html” in the description. Do not add .csv to the ones that have html in the description. Once you have these figured out and working, you can add new plugins.

5 Likes

Is there a good tutorial about making KiCad plugins work? I see them in the directory, I find links to writing plug ins, but I do not know how to download, add, and use plug ins. I posted in the KiCad forum but no response yet. I need baby steps for this part to get started.

OK, it works! The person who wrote the KiCad Action Plugins posted on the KiCad list. Instructions for plugins are usually in the readme file. Here is a link to the instructions for the action plugins.

Here are notes from my installation experience.

  1. The new folder, ‘C:\Users[USERNAME]\AppData\Roaming\kicad\scripting\plugins’ has to be created. It does not install with KiCad. The KiCad folder ‘C:\Program Files\KiCad\share\kicad\scripting\plugins’ is not a good place because the folder may be overwritten by a KiCad update.
  2. The folder depth can only be one deep. Adding the folder “Kicad_action_plugins” with the subdirectories in place to the new plugins folder does not work.
  3. In Windows, you will be asked for permission to copy files to the new folder in C:\Users\username\AppData\Roaming\kicad\scripting\plugins Does this mean that the folder is still writable by KiCad and is there a way to test this? Everything seems to work!
  4. New menu items appear in the Pcbnew menu Tools > External Plugins.
1 Like

So been re-teaching myself kicad the past few days…and have a schematic far enough I’m looking to generate a BOM and build a board for it. I have to say KiCad has come a long way since I last tried it 5 years ago. It still infuriates me in some little ways…but I’m pretty sure I can get used to them.

I have a license for Eagle since I have Fusion360…but apparently as of v9 Eagle removed the CAM processor they had for generating inverted PDF’s which is rather important for the way I’m looking to make DIY boards. There are work arounds but they’re really clunky. The cleanest one is to export as inverted Gerbers. But then you need a 3rd party gerber viewer to print them…and if you want to put multiple boards on one piece of transparency it gets REALLY ugly.

With kicad I can just print to an inverted PDF and then open that in photoshop where I can then arrange as many as I want on one sheet for printing. Not idea but a lot easier and cleaner than the Eagle method.

Anyway…I’m trying @analogoutput’s markdown BOM generator…but getting an error:

Command error. Return code 1
Error messages:
Traceback (most recent call last):
  File "C:\Users\jhite\AppData\Roaming\kicad\scripting\plugins/bom_group_md.py.py", line 88, in <module>
    md = md.replace('<!--SOURCE-->', r.group(1))
AttributeError: 'NoneType' object has no attribute 'group'

Note I’ve tried putting the script in c:\program files\kicad\scripting\plugins as well and it gives the same error. The kicad_netlist_reader.py file is there in both locations…but it seems like either it’s not working or it’s not generating the expected output.

I know enough python to muddle my way around…it looks like the problem is with ‘r’ which is created on line 87 and appears to be trying to load a .sch file. But…I’m not sure what re is…I see it’s imported so I assume it’s a Python library (I’m guessing one for reading files?) and I’m guessing the problem is it’s trying to open the .sch file for my project and not finding it…maybe because of windows vs. @analogoutput being on linux?

Any input on this AO? Or anyone else use the script on Windows?

I’m going back to routing for now and will mess with this more tomorrow.

1 Like

Ok…didn’t fee like going back to the ratsnest just yet.

So I see that re is actually the Python regex library. Makes sense.

And that line is actually searching in ‘s’ which according to the line above comes from net which is the output from the kicad_netlist_reader

So…it looks like it probably is a problem with the netlist_reader after all. But I’m too tired to dig any deeper than that tonight :sleeping:

1 Like

If you have the PS step anyway in your pipeline, it really isn’t that much work to flip a layer after importing the pdf…
Not that I recommend eagle, the free version has so many limitations it is close to useless.

Me too :slight_smile:
The “high-level” workflow is still very 90’s, where you have to export/import your netlist all the time…

1 Like

This means that r is None, instead of an re match object, which means the regexp didn’t match (and someone didn’t add enough error handling :grinning:).

2 Likes

It’s looking in the string s for a match to the regular expression ^.*/(.*)\.sch and not finding it.

s is the result of a call to net.getSource() from the kicad_netlist_reader module. It’s supposed to return the path to the schematic file.

I didn’t write bom_group_md.py from scratch, I adapted it from another script distributed with KiCad, and that part of the code is unchanged from the other script, so if it doesn’t work, I would think other BOM scripts also would fail the same way. If not maybe you could look into the other scripts and see if they do something different.

You could try printing s to see what net.getSource() is returning.

Alternatively you could just comment out lines 87 and 88 and have <!--SOURCE--> appear in your BOM where the file name is supposed to be.

2 Likes

Looks like juggle is using Windows. Is the filename normalized at that point?

(fwiw, helpers like os.path.basename and os.path.splitext are more robust than regexps.)

1 Like