KiBoM - Python BOM Generation tool


#21

Hello!
I would like to see matching of components on their Manufacturers part numbers, MFPN. This is generally considered a good thing to add. I wish it was a default field in Kicad already, now i add it manually, but since it is a bit tedious for resistors and such, could their be some kind of configuration, so that i migh manually add which fields to group on.

That way i could use the MFPN for most parts, and leave tolerance and such empty, for resistors i could instead leave MFPN empty, If i then create my groupings based upon both MFPN and Tolerance for example, i would get the groupings i wanted.

Thanks for your script and effort anyway!


#22

Hey all,

I have made some improvements to the script (the README.md file explains them all) https://github.com/SchrodingersGat/KiBoM

Basically:

a) Grouping columns can now be specified by the user in the .ini preferences file (you can even remove the default grouping columns if required)

b) The regex matching now works on a component level. You can specify various regex to determine if an individual component is included OR excluded (read the docs!)

c) The logic by which a part is “fitted” or “not fitted” is now simplified and explained

d) You can specify that individual components will be included or excluded with “configurations” i.e. only load some components in the “Production” build. This is all laid out in the docs.

e) You can specify in the .ini file if blank fields should count as a “conflict” (making a new line in the BoM) or if they will be merged with a non-blank field where all the other fields match


#23

Hi @SchrodingersGat
I found a little bug when the script is writing html output in case of utf-8 chars (in my case it was 125°C)
I had to substitute

        html.write('\t<meta charset="ISO-8859-1">\n') #UTF-8 encoding for unicode support

to

       html.write('\t<meta charset="UTF-8">\n') #UTF-8 encoding for unicode support

probably it is just an oversight, considering your utf-8 comment :smiley:
thanks a lot for the new implementation of the grouping fields

Maurice


#24

Thanks for the heads-up @maui, fixed :slight_smile:


#25

Hi!
I will append my issue here since I believe it is pertinent to the thread.
I am trying to use the KiBoM tool with the PCB Configuration feature. But I can’t make it work.
I’ve added the fit_field to the schematic and filled with the required information.
The i’ve updated the BOM.ini file with the following information.
> ; Field name used to determine if a particular part is to be fitted
**fit_field = ‘**C00001’

I need to remove from the BOM file the items that are marked as “-C00001”

The only clue that I’ve is that the tool is issuing a warning saying “Field conflict: (J8 J17 J18) [fit_field] : ‘-C00001’ <- '”+Debug"’"
And looks like it is being generated because two different instances of the same part have different “fit_field” information

Anyone has used this feature before?

Thanks in advance


#26

Hi @mcarra there’s a slight misunderstanding in your usage of the fit_field parameter.

The fit_field must specify which field the script looks in to determine if a particular part is included in the BOM. In your example above, you have defined this as C0000:

Which means the script looks for a field called C00001 (which does not exist).

If you change the line to:

fit_field = 'fit_field' then it should work with your current field naming. Or you can change this to whatever you want.

The key is that you do not specify the contents of this field in the .ini. file

Thanks


#27

Hi!
I’ve corrected my bom.ini file with the following statement:

fit_field = ‘Config’

then i’ve updated the Config field with the sentence “-C00001”

Saved all and run the BOM tool with:

python “/home/cmartin/Desktop/KiBoM-master/KiBOM_CLI.py” “%I” “%O” “-r C00001”

And the part is still there:

Any clue?

Thanks in advance.
Martín


#28

Sorry for the delay.

In your command line argument, remove the quotes around “-r C00001”

i.e.

python "/home/cmartin/Desktop/KiBoM-master/KiBOM_CLI.py" "%I" "%O" -r C00001


#29

Excelent! It worked as expected!

I have another question regarding the tool: Can I set the fields that I want to show in the list?
As I can see from the documentation the tool automatically appends the field if it appears in one of the components.

I only want to see reference, value and ManufacturerPN

Any Idea on how to do this?

Thanks in advance!

Martín


#30

Hi

I keep getting an error message when using KiBoM. Have added KiBOM_CLI.py and pressed Generate.
Found one similar error, that suggested to resave the .sch file to ANSI. But this had no effect.

Command error. Return code 1

Error messages:
Traceback (most recent call last):
File “C:/Program Files/KiCad/bin/KiBoM/KiBOM_CLI.py”, line 160, in
output_file = fname + “_” + net.getVersion() + “.” + fext
UnicodeDecodeError: ‘ascii’ codec can’t decode byte 0xf8 in position 65: ordinal not in range(128)


#31

Hi @Martin123 I’ve fixed a few similar errors recently - it would appear in this case that the schematic version text contains some non ASCII characters (or the schematic file name itself).

Can you post the contents of your schematic filename and version / revision string so I can run some tests here and fix the issue?


#32

Thanks for the quick reply.
I just sent you the entire project in PM

Martin


#33

Thank you for this plugin which is very helpfull.

I added the fiel Config and the value +test in one of my componant and when I do
python “C:\Users\myUserName\Downloads\KiBoM-master/KiBOM_CLI.py” “%I” “%O” -r test
or
python “C:\Users\myUserName\Downloads\KiBoM-master/KiBOM_CLI.py” “%I” “%O”
it appears or not in the BOM file.

However, I tried -test and either I do
python “C:\Users\myUserName\Downloads\KiBoM-master/KiBOM_CLI.py” “%I” “%O” -r test
or
python “C:\Users\myUserName\Downloads\KiBoM-master/KiBOM_CLI.py” “%I” “%O”
I never have the component in the BOM file.

Did I do something wrong ? Is it a bug ?

Also is it possible to have several variants by writing +test -prod for a same component ? I tried it but it did not work.


#34

I’m not sure if this is a good place for this question.
I just started to use this tool and the first project I tried barfed. Apparently it didn’t like the part because it’s an alias. Here’s the section in the library that shows this part:

QUAD_OP-AMP

DEF QUAD_OP-AMP U 0 20 Y Y 4 F N
F0 “U” 0 200 50 H V L CNN
F1 “QUAD_OP-AMP” 0 -200 50 H V L CNN
F2 “” -50 100 50 H V C CNN
F3 “” 50 200 50 H V C CNN
ALIAS LM324 TLC274 TL074 LM324N LM324AN MCP6004
$FPLIST
SOIC*
DIP*
TSSOP*
SSOP*
MSOP*
$ENDFPLIST
DRAW
P 4 0 1 10 -200 200 200 0 -200 -200 -200 200 f
X V+ 4 -100 150 0 D 0 50 0 1 W
X V- 11 -100 -150 0 U 0 50 0 1 W
X ~ 1 300 0 100 L 50 50 1 1 O
X - 2 -300 100 100 R 50 50 1 1 I
X + 3 -300 -100 100 R 50 50 1 1 I
X + 5 -300 -100 100 R 50 50 2 1 I
X - 6 -300 100 100 R 50 50 2 1 I
X ~ 7 300 0 100 L 50 50 2 1 O
X ~ 8 300 0 100 L 50 50 3 1 O
X - 9 -300 100 100 R 50 50 3 1 I
X + 10 -300 -100 100 R 50 50 3 1 I
X + 12 -300 -100 100 R 50 50 4 1 I
X - 13 -300 100 100 R 50 50 4 1 I
X ~ 14 300 0 100 L 50 50 4 1 O
ENDDRAW
ENDDEF

And here’s the message:

python “C:/SVN/KiCAD/KiBoM-master/KiBOM_CLI.py” -v “C:/SVN/KiCAD/Projects/TCU-Steering-Copy/TCU-Steering.xml” “C:/SVN/KiCAD/Projects/TCU-Steering-Copy/TCU-Steering”
Input: C:\SVN\KiCAD\Projects\TCU-Steering-Copy\TCU-Steering.xml
Config: C:\SVN\KiCAD\Projects\TCU-Steering-Copy\bom.ini
missing libpart for ref: U36 TL074 TCU-Steering-cache
Excluding ‘MK1’: Field ‘Part’ (Mounting_Hole_PAD) matched ‘mount.*hole’
Excluding ‘MK10’: Field ‘Part’ (Mounting_Hole_PAD) matched ‘mount.*hole’
Excluding ‘MK11’: Field ‘Part’ (Mounting_Hole_PAD) matched ‘mount.*hole’
Excluding ‘MK12’: Field ‘Part’ (Mounting_Hole_PAD) matched ‘mount.*hole’
Excluding ‘MK2’: Field ‘Part’ (Mounting_Hole_PAD) matched ‘mount.*hole’
Excluding ‘MK3’: Field ‘Part’ (Mounting_Hole_PAD) matched ‘mount.*hole’
Excluding ‘MK4’: Field ‘Part’ (Mounting_Hole_PAD) matched ‘mount.*hole’
Excluding ‘MK5’: Field ‘Part’ (Mounting_Hole_PAD) matched ‘mount.*hole’
Excluding ‘MK6’: Field ‘Part’ (Mounting_Hole_PAD) matched ‘mount.*hole’
Excluding ‘MK7’: Field ‘Part’ (Mounting_Hole_PAD) matched ‘mount.*hole’
Excluding ‘MK8’: Field ‘Part’ (Mounting_Hole_PAD) matched ‘mount.*hole’
Excluding ‘MK9’: Field ‘Part’ (Mounting_Hole_PAD) matched ‘mount.*hole’
Traceback (most recent call last):
File “C:/SVN/KiCAD/KiBoM-master/KiBOM_CLI.py”, line 124, in
groups = net.groupComponents(components)
File “C:\SVN\KiCAD\KiBoM-master\bomlib\netlist_reader.py”, line 426, in groupComponents
g.updateFields(self.prefs.useAlt, self.prefs.altWrap)
File “C:\SVN\KiCAD\KiBoM-master\bomlib\component.py”, line 471, in updateFields
self.fields[ColumnList.COL_REFERENCE] = self.getAltRefs(wrapN)
File “C:\SVN\KiCAD\KiBoM-master\bomlib\component.py”, line 431, in getAltRefs
return S.flush(’ ', N=wrapN)
File “C:\SVN\KiCAD\KiBoM-master\bomlib\component.py”, line 347, in flush
if N!=None and c%N==0 and c!=0:
ZeroDivisionError: integer division or modulo by zero

Does anyone know how I can fix this problem?


#35

Hi @kcminer this is a new one. I’ve just made a commit which should fix this, please grab the latest version of KiBOM and see if it works for you now…


#36

Thank you for the swift response. Unfortunately, this didn’t seem to fix the problem. However, the problem may be elsewhere. I replaced the part with a same part from the regular library and the problem went away. It generated a different entry in the library cache. Somehow the library cache may have been stuffed with wrong information.

While playing with the bom.ini file, I noticed that if I set ‘use_alt’ to 1 it generates a divide by 0 error. That’s ok though since I just wanted to see how this behaved and I can live with this set to 0.

This is a great addition to Kicad’s built-in scripts. I wish it’s incorporated into the released version.