KiCad and BOM (2)

Marutsu is an electronics component vendor in Japan. They accept BOM files in the following format;

It seems that they only understand Japanese language encoded in Shift_JIS. This is somewhat unfortunate, but the basic idea is always the same.

# coding: utf-8
import xml.etree.ElementTree as ET
import re

print('"型番","メーカー名","数量"')

tree = ET.parse('RF-ATT.xml')
root = tree.getroot()

regex = r'R[0-9]+'

for node in root.iter('comp'):
	name = node.attrib.get('ref')
	if re.search(regex, name):
		for value in node.iter('value'):
			string = '1/4WキンピR '+value.text+'Ω,KOA,1'
			print(string)

This is a python program that converts the XML file (intermediate net list) from KiCad to a BOM file to be uploaded to Marutsu.

% python xml2bom.py | nkf -s > BOM.csv
$ cat BOM.csv | nkf -w
"型番","メーカー名","数量"
1/4WキンピR 1.8KΩ,KOA,1
1/4WキンピR 1.8KΩ,KOA,1
1/4WキンピR 3Ω,KOA,1
1/4WキンピR 910Ω,KOA,1
1/4WキンピR 910Ω,KOA,1
1/4WキンピR 5.6Ω,KOA,1
1/4WキンピR 300Ω,KOA,1
1/4WキンピR 300Ω,KOA,1
1/4WキンピR 18Ω,KOA,1
1/4WキンピR 220Ω,KOA,1
1/4WキンピR 220Ω,KOA,1
1/4WキンピR 24Ω,KOA,1
1/4WキンピR 150Ω,KOA,1
1/4WキンピR 150Ω,KOA,1
1/4WキンピR 39Ω,KOA,1
1/4WキンピR 100Ω,KOA,1
1/4WキンピR 100Ω,KOA,1
1/4WキンピR 75Ω,KOA,1
1/4WキンピR 62Ω,KOA,1
1/4WキンピR 62Ω,KOA,1
1/4WキンピR 240Ω,KOA,1

After uploading the BOM file, you will have;

and you are ready to place an order.

KiCad and BOM

Let’s try creating a BOM (Bill Of Materials) file that fits your own convenience.

Firstly, export the intermediate netlist file without using any plugins.

Then, you will get an XML file something like the above.

# filename = xmlparse.pl
import xml.etree.ElementTree as ET
tree = ET.parse('RF-ATT.xml')
root = tree.getroot()

for value in root.iter('value'):
	print(value.text)

A short python program to parse an XML tree will give you the following results.

% python xmlparse.pl

Conn_Coaxial
Conn_Coaxial
SW-6P
1800
1800
3
SW-6P
910
910
5.6
SW-6P
300
300
18
SW-6P
220
220
24
SW-6P
150
150
39
SW-6P
100
100
75
SW-6P
62
62
240

Or by adding a shell script:

% xmlparse.py | sort | uniq -c

   2 100
   2 150
   1 18
   2 1800
   2 220
   1 24
   1 240
   1 3
   2 300
   1 39
   1 5.6
   2 62
   1 75
   2 910
   2 Conn_Coaxial
   7 SW-6P

This simple output may be of some use depending on the situation, but what you really wish to get is a list containing part numbers and/or part names that your favorite local parts vendor will understand.