[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: gEDA-user: generate BOM with coalesced refdes's
Here's a Python script I tossed together the other day as a (Python)
learning exercise. The column titles are hard-coded, but it will make a
BOM for each *.sch in the directory. To execute, save it as
"prettyBOM.py" in your schematic directory and run "python prettyBOM.py"
from the command line, again in your schematic directory.
-Ethan
from string import *
import csv
from csv import *
import pdb
import sys
import os
for arg in sys.argv:
print arg
##print sys.argv[1]
##pdb.set_trace()
##name = sys.argv[1]
f=os.popen("ls *.sch")
sch_files = []
for ln in f.readlines():
sch_files.append(ln.split(".")[0])
print sch_files[0]
for name in sch_files:
os.system("gnetlist -g bom -o " + name + ".bom " + name + ".sch")
data = csv.reader(open(name + '.bom'),delimiter='\t')
rowNum = 0
rowData = [[]]
d = {}
for row in data:
if rowNum == 0:
colTitles = row
else:
data1 = row[4]
data2 = row[5]
if d.has_key(data1) == False:
d[data1] = {}
if d[data1].has_key(data2) == False:
d[data1][data2] = [[],[]]
d[data1][data2][0].append(row[1])
if len(d[data1][data2][0]) == 1:
d[data1][data2][1] = ([row[2],row[3]])
rowNum += 1
dataOut = []
colTitles[0] = 'Qty'
colTitles.insert(0,'#')
dataOut.append(colTitles[0:6])
rowNum = 0
for mfg in d:
for pn in d[mfg]:
rowNum += 1
rowDat = d[mfg][pn]
dataOut.append([rowNum,
len(rowDat[0]),
join(rowDat[0], ", "),
rowDat[1][0],
mfg,
pn,
rowDat[1][1]])
outFile = open(name + '.bom','w')
outWriter = csv.writer(outFile, delimiter = '\t')
for row in dataOut:
outWriter.writerow(row)
if outFile.closed == False:
outFile.close()
Mark Rages wrote:
> Hi I want a BOM for assembly that has refdes's grouped together by an
> attribute ("part_number") and a "qty" column added. This would be
> nicer for assembly people and ordering parts.
>
> Is there a way to do this?
>
> Regards,
> Mark
> markrages@gmail
>
_______________________________________________
geda-user mailing list
geda-user@xxxxxxxxxxxxxx
http://www.seul.org/cgi-bin/mailman/listinfo/geda-user