Trying to do somethingh a bit different with the BOM generation

I am using the eschema for something a bit different, wiring diagrams and the connector BOM. So I have put fields into each connector symbol number for the various pins used and this is filled in with the number of pins that connector has. So when I export my BOM I have a column for each pin type and any connector that uses that pin will will have the quantity in that column. But, this means that if I then total that column I will not get the total number of the pins in that design, just the total number of pins taking one of each connector because if say one connector is used 5 times and has 10 pins I will only have 10 listed not 50.

Is there a way to multiply any of the values from the fields by the line number so that each line has the total number of pins for that part type? I could then add up the columns to get the total across the design.

I know this is unorthodox but it would be nice to get it to work. I have made an attempt at changing the python script but KiCad just hangs when I try to run it so I have upset something.

@Sparky_Labs What don’t you try to generate a “normal” BOM then post-process the data refactoring on the generated BOM? That way you avoid “upsetting” the BOM export script and your work stays independent from the traditional export methods.

I see what you are asking for and it makes sense since you are looking for a way on how to do this that is mostly native to KiCAD.

There is a simple way to actually accomplish what you want. First it will require that you have some knowledge of how to use Python. Starting with one of the included Python BOM generators. You can then modify this script to output whatever you want for your specific BOM.

If stuck look at how people have implemented the JLC BOM plugin.

Well yes that would be ideal but I would not know where to start which is why I was hoping to bend the tool I have and sort of understand my way.

With Python, manipulating CSV files is quite entry level. Don’t hesitate to ask on SO or here if you need help with your project. Or as @ManOnTheMoon said, you could give it another shot at making the BOM generator bend your way.

Yea, maybe it’s time to learn python which I believe can be used for web stuff as well?

I would say CSV files in python are simple, but working with the KiCAD Python API is not. Currently the API is not well documented, and examples are very scarce.

I would start here,

That is the most basic python script for KiCAD BOM generation. This will generate a sorted list of components by reference designator.

From this you will need to modify line

writerow( out, ['Ref', 'Value', 'Footprint', 'Datasheet', 'Manufacturer', 'Vendor'] )

This line is what sets what a column means. Add your new header here, be is “Pin Type” or “Pin Count” or whatever you want to add.

Next you will need to modify

writerow( out, [c.getRef(), c.getValue(), c.getFootprint(), c.getDatasheet(),
        c.getField("Manufacturer"), c.getField("Vendor")])

Since you are using custom fields, you will need to use getField() interface to get the information you want.

For example if a part has a field called “Pin Type” then you would write c.getField("Pin Type")

All this will be written to a CSV file.

One last note is that this python script should be called from the BOM interface. You’ll probably have to import the script into the interface but from there t can be called as normal.

Yep, that is as far as I got. I tried to multiply the field by the line quantity number but that must be too much so as suggested I guess I should reprocess the outputted file.

Everything should be doable within KiCAD Python scripts. KiiCAD uses a full python interpreter so anything that Python so all post processing should be able to be done within KiCAD.

Well the field when using c.getField() returns a string. This would have to be converted to a integer.

In the script provided there is one line per component, if you want to combine multiple components that are the same into a single line, then you’ll have to use a different base script. The script for that is

This combines same entries. Then you use the len(group) which is the number of components with the same value, and multiply that by int(c.getField("Pin Type") to get the total pin count.

With the above BOM scripts there really should be no need for post processing. What you are trying to do can be accomplished in KiCAD.

Three modifications to that second script should get you to what you need.

hm, I think I took len(group) to be the number, maybe I was wrong. yes I’d not be surprised if it is all possible. I just need to learn some python and understand what it is doing and how to modify it. So far I have just been guessing.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.