Mendel90 icon indicating copy to clipboard operation
Mendel90 copied to clipboard

bom csv

Open createthis opened this issue 11 years ago • 0 comments

In case anyone is interested in generating a bom csv, here is a little diff to sort out the columns and such. I just copy and paste this code into bom.py, above the "Printed:" line, then I generated the BOM, then I cut and pasted the csv into another file and imported into a spreadsheet.

diff --git a/bom.py b/bom.py
index 9ca4639..0b96ddb 100755
--- a/bom.py
+++ b/bom.py
@@ -65,6 +65,35 @@ class BOM:
             print >> file, "%3d" % self.vitamins[part], description

         print >> file
+        print >> file, "CSV:"
+
+        if breakdown:
+            longest = 0
+            for ass in self.assemblies:
+                name = ass.replace("_assembly","")
+                longest = max(longest, len(name))
+            for ass in sorted(self.assemblies):
+                name = ass.replace("_assembly","").replace("_"," ").capitalize()
+               print >> file, " %s|" % name,
+            print >> file
+
+        for part in sorted(self.vitamins):
+            if ': ' in part:
+                part_no, description = part.split(': ')
+            else:
+                part_no, description = "", part
+            if breakdown:
+                for ass in sorted(self.assemblies):
+                    bom = self.assemblies[ass]
+                    if part in bom.vitamins:
+                        file.write("%2d|" % bom.vitamins[part])
+                    else:
+                        file.write("  |")
+            print >> file, "%3d|" % self.vitamins[part], description
+
+
+
+        print >> file
         print >> file, "Printed:"
         for part in sorted(self.printed):
             if breakdown:

Quick and dirty, and not a bit elegant, I know. But maybe it saves someone time.

createthis avatar Dec 25 '12 03:12 createthis