What I was trying to tell you in an earlier post is that the information is split across two files, keyed by RefDes, and if someone (you?) is good at programming, it can be extracted into another column, or separate BOM files.
Ok, since I couldn’t resist a quick programming exercise I wrote this Python script:
#!/usr/bin/env python3
"""Read CPL and BOM CSV files and add a layer column to BOM file"""
import sys
import argparse
import csv
def process(cpl, bom):
"""Read CPL saving layer, then iterate through BOM, adding layer"""
layer = {} # map from RefDes to layer
with open(cpl) as filehandle:
reader = csv.DictReader(filehandle)
for row in reader:
layer[row['Designator']] = row['Layer']
with open(bom) as filehandle:
reader = csv.DictReader(filehandle)
reader.fieldnames.append('Layer')
writer = csv.DictWriter(sys.stdout, reader.fieldnames)
writer.writeheader()
for row in reader:
if ',' in row['Designator']: # handle comma separated designators
for designator in row['Designator'].split(','):
row['Designator'] = designator
row['Layer'] = layer[designator]
writer.writerow(row)
else:
row['Layer'] = layer[row['Designator']]
writer.writerow(row)
def main():
"""Main routine"""
# pylint: disable=global-statement
parser = argparse.ArgumentParser(
description='Read CPL and BOM CSV files and add a layer column to BOM file')
parser.add_argument('CPL')
parser.add_argument('BOM')
args = parser.parse_args()
try:
process(args.CPL, args.BOM)
except IOError:
print(f"Cannot process input files")
if __name__ == '__main__':
main()
Given this CPL:
Designator,Val,Package,Mid X,Mid Y,Rotation,Layer
"C1","100n","C_0603_1608Metric",132.737200,-61.595000,-90.000000,top
"Q1","MMBT5551","SOT-23",115.017200,-59.055000,0.000000,top
"Q2","MMBT5551","SOT-23",115.017200,-63.500000,0.000000,top
"Q3","MMBT5551","SOT-23",115.017200,-67.945000,0.000000,bottom
"Q4","MMBT5551","SOT-23",106.237200,-71.120000,0.000000,bottom
"Q10","MMBT5551","SOT-23",96.046700,-55.880000,0.000000,bottom
"Q11","MMBT5551","SOT-23",96.046700,-60.960000,0.000000,bottom
"Q12","MMBT5551","SOT-23",96.046700,-66.040000,0.000000,bottom
"Q13","MMBT5551","SOT-23",96.046700,-71.120000,0.000000,bottom
"Q14","MMBT5551","SOT-23",101.126700,-55.880000,0.000000,bottom
"Q15","MMBT5551","SOT-23",101.126700,-60.960000,0.000000,bottom
"Q16","MMBT5551","SOT-23",101.126700,-66.040000,0.000000,bottom
"Q17","MMBT5551","SOT-23",101.126700,-71.120000,0.000000,bottom
"Q18","MMBT5551","SOT-23",106.206700,-55.880000,0.000000,top
"Q19","MMBT5551","SOT-23",106.206700,-60.960000,0.000000,top
"R1","22k","R_0603_1608Metric",120.732200,-60.325000,0.000000,top
"R2","22k","R_0603_1608Metric",120.732200,-64.135000,0.000000,top
"R3","22k","R_0603_1608Metric",120.542200,-67.945000,0.000000,bottom
"R4","22k","R_0603_1608Metric",105.977900,-67.310000,0.000000,bottom
"R9","22k","R_0603_1608Metric",132.737200,-66.040000,-90.000000,bottom
"R10","22k","R_0603_1608Metric",110.047200,-56.515000,0.000000,bottom
"R11","22k","R_0603_1608Metric",110.047200,-60.960000,0.000000,bottom
"R12","22k","R_0603_1608Metric",110.047200,-66.040000,0.000000,top
"R13","22k","R_0603_1608Metric",110.047200,-70.485000,0.000000,top
and this BOM:
Comment,Designator,Footprint,LCSC
"100n","C1","Capacitor_SMD:C_0603_1608Metric","C14663"
"MMBT5551","Q1,Q2,Q3,Q4,Q10,Q11,Q12,Q13,Q14,Q15,Q16,Q17,Q18,Q19","Package_TO_SOT_SMD:SOT-23","C2145"
"22k","R1,R2,R3,R4,R9,R10,R11,R12,R13","Resistor_SMD:R_0603_1608Metric","C31850"
running the program with ./addlayer.py modularnixie-pos.csv modularnixie.csv
produces:
Comment,Designator,Footprint,LCSC,Layer
100n,C1,Capacitor_SMD:C_0603_1608Metric,C14663,top
MMBT5551,Q1,Package_TO_SOT_SMD:SOT-23,C2145,top
MMBT5551,Q2,Package_TO_SOT_SMD:SOT-23,C2145,top
MMBT5551,Q3,Package_TO_SOT_SMD:SOT-23,C2145,bottom
MMBT5551,Q4,Package_TO_SOT_SMD:SOT-23,C2145,bottom
MMBT5551,Q10,Package_TO_SOT_SMD:SOT-23,C2145,bottom
MMBT5551,Q11,Package_TO_SOT_SMD:SOT-23,C2145,bottom
MMBT5551,Q12,Package_TO_SOT_SMD:SOT-23,C2145,bottom
MMBT5551,Q13,Package_TO_SOT_SMD:SOT-23,C2145,bottom
MMBT5551,Q14,Package_TO_SOT_SMD:SOT-23,C2145,bottom
MMBT5551,Q15,Package_TO_SOT_SMD:SOT-23,C2145,bottom
MMBT5551,Q16,Package_TO_SOT_SMD:SOT-23,C2145,bottom
MMBT5551,Q17,Package_TO_SOT_SMD:SOT-23,C2145,bottom
MMBT5551,Q18,Package_TO_SOT_SMD:SOT-23,C2145,top
MMBT5551,Q19,Package_TO_SOT_SMD:SOT-23,C2145,top
22k,R1,Resistor_SMD:R_0603_1608Metric,C31850,top
22k,R2,Resistor_SMD:R_0603_1608Metric,C31850,top
22k,R3,Resistor_SMD:R_0603_1608Metric,C31850,bottom
22k,R4,Resistor_SMD:R_0603_1608Metric,C31850,bottom
22k,R9,Resistor_SMD:R_0603_1608Metric,C31850,bottom
22k,R10,Resistor_SMD:R_0603_1608Metric,C31850,bottom
22k,R11,Resistor_SMD:R_0603_1608Metric,C31850,bottom
22k,R12,Resistor_SMD:R_0603_1608Metric,C31850,top
22k,R13,Resistor_SMD:R_0603_1608Metric,C31850,top
Do what you like with this script. Have fun.