From 5ae040079e5047bfe0839ff57548bf5ba26b31d9 Mon Sep 17 00:00:00 2001 From: Chris Palmer Date: Sun, 21 Jul 2019 18:58:38 +0100 Subject: [PATCH] Now shows the CNC routed parts in the master BOM and total parts count. --- examples/MainsBreakOutBox/readme.md | 9 +++-- scripts/views.py | 61 +++++++++++++++++------------ 2 files changed, 43 insertions(+), 27 deletions(-) diff --git a/examples/MainsBreakOutBox/readme.md b/examples/MainsBreakOutBox/readme.md index 585160c..75d4472 100644 --- a/examples/MainsBreakOutBox/readme.md +++ b/examples/MainsBreakOutBox/readme.md @@ -31,6 +31,7 @@ Earth leakage can be measured Canadian CSA style by disconnected the neutral lin ## Parts list | Base | Feet | Mains In | Main | TOTALS | | |--:|--:|--:|--:|--:|:--| +| | | | | | **Vitamins** | |   .  |   .  |   .  |   2  |   2  |    4mm shielded jack socket blue | |   .  |   .  |   .  |   1  |   1  |    4mm shielded jack socket brown | |   .  |   .  |   .  |   2  |   2  |    4mm shielded jack socket green | @@ -47,9 +48,11 @@ Earth leakage can be measured Canadian CSA style by disconnected the neutral lin |   .  |   .  |   1  |   1  |   2  |    Wire blue 30/0.25mm strands, length 150mm - not shown | |   .  |   .  |   2  |   .  |   2  |    Wire brown 30/0.25mm strands, length 150mm - not shown | |   .  |   .  |   1  |   1  |   2  |    Wire green & yellow 30/0.25mm strands, length 150mm - not shown | -| | | | | | **3D Printed parts** | -|   .  |   4  |   .  |   .  |   4  |    foot.stl | -|   1  |   .  |   .  |   .  |   1  |    socket_box.stl | +|   2  |   16  |   14  |   18  |   50  |   Total vitamins count | +| | | | | | **3D printed parts** | +|   .  |   4  |   .  |   .  |   4  |   foot.stl | +|   1  |   .  |   .  |   .  |   1  |   socket_box.stl | +|   1  |   4  |   .  |   .  |   5  |   Total 3D printed parts count | [Top](#TOP) diff --git a/scripts/views.py b/scripts/views.py index c04fd5e..efac634 100644 --- a/scripts/views.py +++ b/scripts/views.py @@ -219,36 +219,49 @@ def views(target, do_assemblies = None): # Global BOM # print('\n## Parts list', file = doc_file) - vitamins = {} - printed = {} - routed = {} + types = ["vitamins", "printed", "routed"] + headings = {"vitamins" : "vitamins", "printed" : "3D printed parts", "routed" : "CNC routed parts"} + things = {} + for t in types: + things[t] = {} for ass in flat_bom: - for v in ass["vitamins"]: - if v in vitamins: - vitamins[v] += ass["vitamins"][v] - else: - vitamins[v] = ass["vitamins"][v] - for p in ass["printed"]: - if p in printed: - printed[p] += ass["printed"][p] - else: - printed[p] = ass["printed"][p] + for t in types: + for thing in ass[t]: + if thing in things[t]: + things[t][thing] += ass[t][thing] + else: + things[t][thing] = ass[t][thing] for ass in flat_bom: name = ass["name"][:-9].replace('_', ' ').title().replace(' ',' ') print('| %s ' % name, file = doc_file, end = '') print('| TOTALS | |', file = doc_file) + print(('|--:' * len(flat_bom) + '|--:|:--|'), file = doc_file) - for v in sorted(vitamins, key = lambda s: s.split(":")[-1]): - for ass in flat_bom: - count = ass["vitamins"][v] if v in ass["vitamins"] else '.' - print('| %s ' % pad(count, 2, 1), file = doc_file, end = '') - print('| %s | %s |' % (pad(vitamins[v], 2, 1), pad(v.split(":")[1], 2)), file = doc_file) - print(('| ' * len(flat_bom) + '| | **3D Printed parts** |'), file = doc_file) - for p in sorted(printed): - for ass in flat_bom: - count = ass["printed"][p] if p in ass["printed"] else '.' - print('| %s ' % pad(count, 2, 1), file = doc_file, end = '') - print('| %s | %s |' % (pad(printed[p], 2, 1), pad(p, 3)), file = doc_file) + + for t in types: + if things[t]: + totals = {} + heading = headings[t][0:1].upper() + headings[t][1:] + print(('| ' * len(flat_bom) + '| | **%s** |') % heading, file = doc_file) + for thing in sorted(things[t], key = lambda s: s.split(":")[-1]): + for ass in flat_bom: + count = ass[t][thing] if thing in ass[t] else 0 + print('| %s ' % pad(count if count else '.', 2, 1), file = doc_file, end = '') + name = ass["name"] + if name in totals: + totals[name] += count + else: + totals[name] = count + print('| %s | %s |' % (pad(things[t][thing], 2, 1), pad(thing.split(":")[-1], 2)), file = doc_file) + + grand_total = 0 + for ass in flat_bom: + name = ass["name"] + total = totals[name] if name in totals else 0 + print('| %s ' % pad(total if total else '.', 2, 1), file = doc_file, end = '') + grand_total += total + print("| %s | %s |" % (pad(grand_total, 2, 1), pad('Total %s count' % headings[t], 2)), file = doc_file) + print(file = doc_file) eop(print_mode, doc_file) #