47 lines
1.3 KiB
Python
47 lines
1.3 KiB
Python
# BOM generation script for KiCAD (6+)
|
|
# Last update: 23/03/2025
|
|
# Author: Jorian Zwerver
|
|
|
|
# This scripts formats the BOM to the format of JLCPCB
|
|
# https://jlcpcb.com/help/article/bill-of-materials-for-pcb-assembly
|
|
|
|
"""
|
|
@package
|
|
Generate a comma delimited list (csv file type) in JLCPCB style.
|
|
Components are sorted by reference and grouped by value.
|
|
Fields are (if exist)
|
|
'Comment', 'Designator', 'Footprint', 'JLCPCB Part # (optional)'
|
|
|
|
Command line:
|
|
python "pathToFile/SpecLib/BOM scripts/spectrum_bom_jlcpcb.py" "%I" "%O_JLCPCB.csv"
|
|
"""
|
|
|
|
# Import libraries
|
|
from libs import kicad_netlist_reader
|
|
import csv
|
|
import sys
|
|
|
|
net = kicad_netlist_reader.netlist(sys.argv[1])
|
|
|
|
try:
|
|
f = open(sys.argv[2], 'w')
|
|
except IOError:
|
|
e = "Can't open output file for writing: " + sys.argv[2]
|
|
print(__file__, ":", e, sys.stderr)
|
|
f = sys.stdout
|
|
|
|
# Generate new CSV file with header
|
|
out = csv.writer(f, lineterminator='\n', delimiter=',', quotechar='\"', quoting=csv.QUOTE_ALL)
|
|
out.writerow(['Comment', 'Designator', 'Footprint', 'JLCPCB Part # (optional)'])
|
|
|
|
grouped = net.groupComponents()
|
|
for group in grouped:
|
|
refs = ", ".join(component.getRef() for component in group)
|
|
component = group[0]
|
|
|
|
out.writerow([
|
|
component.getValue(),
|
|
refs,
|
|
component.getFootprint(),
|
|
component.getField("LCSC")
|
|
]) |