Collapsing BOMs

Say I have managed to coerce a BOM(Bill-of-Materials == what to order to go on a circuit board) out of a netlister. It will be a .csv or similar. It has one line per part on the pcb. The Distributors usually have multiples that are not 1 esp for resistors and similar cheap crap, so the part numbers on each line will typically be sthg like: "1/10x9468510" Also there may be several entries per refdes. Say for washers, bolts and nuts that go with a heatsink. Like the example above but several such entries separated by + or ',' characters (and quoted to avoid leaking columns).

What I'd like to arrive at is another csv with unique part numbers and an amount(maybe rounded up to next multiple). How is that typically done. Is there a python/perl/bash script floating around?

Or at least a search term for whatever this is called...

Reply to
Johann Klammer
Loading thread data ...

It's called a 'script'. ;)

Cheers

Phil Hobbs

Reply to
pcdhobbs

Excel spreadsheet.

Bye Jack

Reply to
jack4747

On 08/21/2018 09:59 AM, snipped-for-privacy@gmail.com wrote:

I mean the `process of collapsing a BOM'. what is /that/ called. Googling for `BOM handling' usually yields far too many UNICODE results to be a useful search term.

Yes, I wrote a script. it's below:

#!/usr/bin/python

# collapse_bom.py

import argparse import sys from fractions import Fraction from pyparsing import commaSeparatedList from math import ceil

parser = argparse.ArgumentParser(description = 'collapses a BOM (Bill of Materials)', formatter_class=argparse.RawDescriptionHelpFormatter, epilog = '''%(prog)s collapses individual lines with the same order numbers into a single line It reads a bom .csv file and collapses identical positions into a single one The top row are labels. it will look for 'nr'. lines with the same nr will be collapsed order numbers may be prefixed by a multiplier 'x' there might be more than one number concatenated by + or , characters the multiplier has higher precedence Example: 1/5x9591664+2/8x2518991 The program will output a csv with only a single order number per line and cumulative amount. The other fields will be quoted concatenations if they differ. It can not handle non rectangular tables.''' ) parser.add_argument('-e','--exact',default = False,type=bool, help = 'output exact amounts. \ boolean. if unset rounds up.') parser.add_argument('-c','--column',default = 'nr',type=str, help = 'The column label used for order numbers. \ default 'nr'.') parser.add_argument('filename', help = 'the input file (CSV with header line. comma and newline separators)') parser.add_argument('output', help = 'the output file (CSV)') args = parser.parse_args() if not args.output or not args.filename: sys.exit(2) if args.filename=='-': f=sys.stdin else: f=open(args.filename,'rt') line=f.readline() def unquote(s): return s.strip('"') header=map(unquote,commaSeparatedList.parseString(line)) linelength=len(header) nr_col=None for i, tok in enumerate(header): if tok==args.column: nr_col=i break

if None==nr_col: f.close() print "Error. Column not found: ",args.column sys.exit(2) p_dict={} for line in f: row=map(unquote,commaSeparatedList.parseString(line)); nrs=row[nr_col] fields=nrs.split('+') if len(fields)==1: fields=nrs.split(',') for nr in fields: n=Fraction(1,1) p=nr; v=nr.split('x') if len(v)==2: w=v[0].split('/') if len(w)==2: n=Fraction(int(w[0]),int(w[1])) else: n=float(v[0]) p=v[1] if p in p_dict: r=p_dict[p] for i, e in enumerate(r): if i==nr_col: r[i]=r[i]+n else: if r[i]!=row[i]: r[i]=r[i]+", "+row[i] p_dict[p]=r else: p_dict[p]=row p_dict[p][nr_col]=n#abusing the order no for amount here

f.close() if args.output=='-': of=sys.stdout else: of=open(args.output,'wt') of.write("Amount, ") for i,e in enumerate(header): of.write(str(e)) if i

Reply to
Johann Klammer

I have one written in VB6 called PartsListProcessor - I've never seen one as part of a package. Mine was done a long time ago for internal use only. If you do any coding at all it's not that hard - if you don't your best bet is to find a pal who does.

MK

Reply to
Michael Kellett

to go on a circuit board)

t on the pcb.

and similar cheap crap,

10"

nuts that go with a heatsink.

racters

amount(maybe rounded up to next multiple).

round?

Sounds to me like you have a fairly complex build process. When I worked f or a defense contractor they had a BOM for each assembly which for higher l evel assemblies referred to the lower level assemblies as components. When you talk about needing multiples of several parts for a heat sink, that is how they would handle that issue I believe. Or maybe your BOM is not comp lete. I would not have a BOM that required me to do further math to get qu antities.

So to answer your question, I have never heard of a term for "collapsing" a BOM. The only thing that I would need to do with a BOM is to multiply the individual items by the quantity of units to be made. But in addition to the "round up" that has to be done for the ordering multiples, it is very c ommon to add a factor to allow for some waste in the assembly process. Ine xpensive passives are often bought at a 10% or even 20% higher quantity for this.

Rick C.

Reply to
gnuarm.deletethisbit

I think the issue is "one component per line" and "one part number per line". Most schematic entry tools can generate either format.

Reply to
krw

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.