diff --git a/examples/MainsBreakOutBox/assemblies/feet_assembly.png b/examples/MainsBreakOutBox/assemblies/feet_assembly.png index fce5a70..1ed5d30 100644 Binary files a/examples/MainsBreakOutBox/assemblies/feet_assembly.png and b/examples/MainsBreakOutBox/assemblies/feet_assembly.png differ diff --git a/examples/MainsBreakOutBox/bom/bom.json b/examples/MainsBreakOutBox/bom/bom.json index 3416c32..8c311a8 100644 --- a/examples/MainsBreakOutBox/bom/bom.json +++ b/examples/MainsBreakOutBox/bom/bom.json @@ -1,67 +1,119 @@ [ { "name": "base_assembly", + "big": null, "count": 1, "assemblies": {}, "vitamins": { - "insert(F1BM3): Heatfit insert M3": 2 + "insert(F1BM3): Heatfit insert M3": { + "count": 2 + } }, "printed": { - "socket_box.stl": 1 + "socket_box.stl": { + "count": 1, + "colour": "dimgrey" + } }, "routed": {} }, { "name": "feet_assembly", + "big": null, "count": 1, "assemblies": { "base_assembly": 1 }, "vitamins": { - "washer(M3_washer): Washer M3 x 7mm x 0.5mm": 8, - "screw(M3_dome_screw, 10): Screw M3 dome x 10mm": 4, - "nut(M3_nut, nyloc = true): Nut M3 x 2.4mm nyloc": 4 + "washer(M3_washer): Washer M3 x 7mm x 0.5mm": { + "count": 8 + }, + "screw(M3_dome_screw, 10): Screw M3 dome x 10mm": { + "count": 4 + }, + "nut(M3_nut, nyloc = true): Nut M3 x 2.4mm nyloc": { + "count": 4 + } }, "printed": { - "foot.stl": 4 + "foot.stl": { + "count": 4, + "colour": "darkorange" + } }, "routed": {} }, { "name": "mains_in_assembly", + "big": null, "count": 1, "assemblies": { "feet_assembly": 1 }, "vitamins": { - ": Wire green & yellow 30/0.25mm strands, length 150mm - not shown": 1, - ": Wire blue 30/0.25mm strands, length 150mm - not shown": 1, - ": Wire brown 30/0.25mm strands, length 150mm - not shown": 2, - "tubing(HSHRNK32): Heatshrink sleeving ID 3.2mm x 15mm - not shown": 3, - "iec(IEC_inlet_atx): IEC inlet for ATX": 1, - "screw(M3_cs_cap_screw, 12): Screw M3 cs cap x 12mm": 2, - "washer(M3_washer): Washer M3 x 7mm x 0.5mm": 2, - "nut(M3_nut, nyloc = true): Nut M3 x 2.4mm nyloc": 2 + ": Wire green & yellow 30/0.25mm strands, length 150mm - not shown": { + "count": 1 + }, + ": Wire blue 30/0.25mm strands, length 150mm - not shown": { + "count": 1 + }, + ": Wire brown 30/0.25mm strands, length 150mm - not shown": { + "count": 2 + }, + "tubing(HSHRNK32): Heatshrink sleeving ID 3.2mm x 15mm - not shown": { + "count": 3 + }, + "iec(IEC_inlet_atx): IEC inlet for ATX": { + "count": 1 + }, + "screw(M3_cs_cap_screw, 12): Screw M3 cs cap x 12mm": { + "count": 2 + }, + "washer(M3_washer): Washer M3 x 7mm x 0.5mm": { + "count": 2 + }, + "nut(M3_nut, nyloc = true): Nut M3 x 2.4mm nyloc": { + "count": 2 + } }, "printed": {}, "routed": {} }, { "name": "main_assembly", + "big": null, "count": 1, "assemblies": { "mains_in_assembly": 1 }, "vitamins": { - ": Wire green & yellow 30/0.25mm strands, length 150mm - not shown": 1, - ": Wire blue 30/0.25mm strands, length 150mm - not shown": 1, - "tubing(HSHRNK32): Heatshrink sleeving ID 3.2mm x 15mm - not shown": 5, - ": Ferrule for 1.5mm^2 wire - not shown": 3, - "mains_socket(Contactum): Mains socket 13A": 1, - "screw(M3_cs_cap_screw, 20): Screw M3 cs cap x 20mm": 2, - "jack_4mm_shielded(\"blue\", 3, \"royalblue\"): 4mm shielded jack socket blue": 2, - "jack_4mm_shielded(\"brown\", 3, \"sienna\"): 4mm shielded jack socket brown": 1, - "jack_4mm_shielded(\"green\", 3): 4mm shielded jack socket green": 2 + ": Wire green & yellow 30/0.25mm strands, length 150mm - not shown": { + "count": 1 + }, + ": Wire blue 30/0.25mm strands, length 150mm - not shown": { + "count": 1 + }, + "tubing(HSHRNK32): Heatshrink sleeving ID 3.2mm x 15mm - not shown": { + "count": 5 + }, + ": Ferrule for 1.5mm^2 wire - not shown": { + "count": 3 + }, + "mains_socket(Contactum): Mains socket 13A": { + "count": 1 + }, + "screw(M3_cs_cap_screw, 20): Screw M3 cs cap x 20mm": { + "count": 2 + }, + "jack_4mm_shielded(\"blue\", 3, \"royalblue\"): 4mm shielded jack socket blue": { + "count": 2 + }, + "jack_4mm_shielded(\"brown\", 3, \"sienna\"): 4mm shielded jack socket brown": { + "count": 1 + }, + "jack_4mm_shielded(\"green\", 3): 4mm shielded jack socket green": { + "count": 2 + } }, "printed": {}, "routed": {} diff --git a/examples/MainsBreakOutBox/scad/bob_main.scad b/examples/MainsBreakOutBox/scad/bob_main.scad index c991e56..f7b8d0d 100644 --- a/examples/MainsBreakOutBox/scad/bob_main.scad +++ b/examples/MainsBreakOutBox/scad/bob_main.scad @@ -173,7 +173,7 @@ module socket_box_stl() { // module base_assembly() assembly("base") { - color(pp1_colour) render() /*clip(ymax = 0)*/ socket_box_stl(); + stl_colour(pp1_colour) render() /*clip(ymax = 0)*/ socket_box_stl(); mains_socket_hole_positions(socket) translate_z(height) diff --git a/examples/MainsBreakOutBox/stls/foot.png b/examples/MainsBreakOutBox/stls/foot.png index 017a793..4ef47c7 100644 Binary files a/examples/MainsBreakOutBox/stls/foot.png and b/examples/MainsBreakOutBox/stls/foot.png differ diff --git a/examples/MainsBreakOutBox/stls/socket_box.png b/examples/MainsBreakOutBox/stls/socket_box.png index 78c2934..1f7a8e0 100644 Binary files a/examples/MainsBreakOutBox/stls/socket_box.png and b/examples/MainsBreakOutBox/stls/socket_box.png differ diff --git a/printed/box_assembly.scad b/printed/box_assembly.scad index 9618f9e..040451d 100644 --- a/printed/box_assembly.scad +++ b/printed/box_assembly.scad @@ -33,7 +33,7 @@ assembly("box") { y = [-1,-1,1,1][corner]; translate([x * (box_width(type) / 2 + 25 * exploded()), y * (box_depth(type) / 2 + 25 * exploded())]) rotate(corner * 90) { - color(pp2_colour) render() + stl_colour(pp2_colour) render() box_corner_profile(type); translate([box_hole_inset(type), box_hole_inset(type)]) @@ -50,7 +50,7 @@ assembly("box") { translate_z(z * (box_height(type) / 2 - box_corner_gap(type) + 50 * exploded())) rotate([z * 90 - 90, 0, 0]) if(bezels && (z > 0 ? top : base)) - color(pp1_colour) render() box_bezel(type, z < 0); + stl_colour(pp1_colour) render() box_bezel(type, z < 0); translate_z(z * (box_height(type) / 2 + sheet_thickness + 50 * exploded())) box_screw_hole_positions(type) diff --git a/printed/cable_grommets.scad b/printed/cable_grommets.scad index b00fa38..604d7d3 100644 --- a/printed/cable_grommets.scad +++ b/printed/cable_grommets.scad @@ -133,12 +133,12 @@ module round_grommet_hole(diameter, h = 100) //! Make a hole for a round grommet drill(corrected_radius(diameter / 2) + wall + clearance, h); module round_grommet_assembly(diameter, thickness, od = undef) { - color(pp1_colour) + stl_colour(pp1_colour) translate_z(wall) vflip() round_grommet_top(diameter, thickness, od); - color(pp2_colour) + stl_colour(pp2_colour) translate_z(-thickness) vflip() round_grommet_bottom(diameter, od); @@ -188,7 +188,7 @@ module mouse_grommet(r, thickness) { //! Make the STL for a mouse grommet } module mouse_grommet_assembly(r, thickness) - color(pp1_colour) + stl_colour(pp1_colour) rotate([-90, 0, 0]) mouse_grommet(r, thickness); diff --git a/printed/corner_block.scad b/printed/corner_block.scad index 46d71c5..b5f1ea8 100644 --- a/printed/corner_block.scad +++ b/printed/corner_block.scad @@ -120,7 +120,7 @@ module corner_block_assembly(screw = def_screw, name = false) //! The printed bl assembly(str("corner_block_M", 20 * screw_radius(screw))) { insert = screw_insert(screw); - color(name ? pp2_colour : pp1_colour) + stl_colour(name ? pp2_colour : pp1_colour) render() corner_block(screw, name) children(); corner_block_h_holes(screw) diff --git a/printed/door_hinge.scad b/printed/door_hinge.scad index a2e1526..26daa0a 100644 --- a/printed/door_hinge.scad +++ b/printed/door_hinge.scad @@ -141,7 +141,7 @@ module door_hinge_assembly(top, door_thickness = 6) { //! The moving assembly th translate([0, pin_y - (thickness + door_thickness / 2), dir * width / 2]) { rotate([90, 0, 180]) - color(pp2_colour) door_hinge(door_thickness); + stl_colour(pp2_colour) door_hinge(door_thickness); rotate([90, 0, 0]) door_hinge_hole_positions() @@ -165,7 +165,7 @@ module door_hinge_static_assembly(top, sheet_thickness = 3) { //! The stationary translate([pin_x, 0, -dir * (stat_width / 2 + washer_thickness(screw_washer(pin_screw)))]) rotate([90, 0, 0]) { - color(pp1_colour) door_hinge_stat_stl(); + stl_colour(pp1_colour) door_hinge_stat_stl(); door_hinge_stat_hole_positions() { screw_and_washer(stat_screw, stat_screw_length); diff --git a/printed/door_latch.scad b/printed/door_latch.scad index 1590ebb..0172710 100644 --- a/printed/door_latch.scad +++ b/printed/door_latch.scad @@ -65,7 +65,7 @@ module door_latch_assembly(sheet_thickness = 3) { //! The assembly for a specifi translate([0, -height - washer_thickness(washer)]) rotate([-90, 0, 0]) { - color(pp1_colour) render() door_latch_stl(); + stl_colour(pp1_colour) render() door_latch_stl(); translate_z(nut_trap_depth) vflip() diff --git a/printed/fixing_block.scad b/printed/fixing_block.scad index 9dfe28d..4e64fb9 100644 --- a/printed/fixing_block.scad +++ b/printed/fixing_block.scad @@ -109,7 +109,7 @@ module fixing_block_assembly(screw = def_screw) pose([55, 180, 25], [0, 4.8, 4.8 assembly(str("fixing_block_M", 20 * screw_radius(screw))) { translate_z(fixing_block_height(screw)) rotate([0, 180, 0]) - color(pp1_colour) render() fixing_block(screw); + stl_colour(pp1_colour) render() fixing_block(screw); insert = screw_insert(screw); diff --git a/printed/flat_hinge.scad b/printed/flat_hinge.scad index 1a1cfda..eecfd24 100644 --- a/printed/flat_hinge.scad +++ b/printed/flat_hinge.scad @@ -133,17 +133,17 @@ assembly(str("hinge_", type[0])) { //! Assembled hinge vitamin(str(": Hinge pin ", w, " x ", 2 * hr, "mm")); - color(pp1_colour) hinge_male(type); + stl_colour(pp1_colour) hinge_male(type); translate([0, -kr, kr]) { rotate([0, 90, 0]) explode(w + 10) - color("silver") cylinder(r = hr , h = w, center = true); + stl_colour("silver") cylinder(r = hr , h = w, center = true); rotate([-angle, 0, 0]) translate([0, -kr, -kr]) rotate(180) - color(pp2_colour) hinge_female(type); + stl_colour(pp2_colour) hinge_female(type); } } diff --git a/printed/foot.scad b/printed/foot.scad index 3cdb23b..fdf63a4 100644 --- a/printed/foot.scad +++ b/printed/foot.scad @@ -73,7 +73,7 @@ module foot_assembly(t = 0, type = foot, flip = false) { //! Assembly with faste screw_length = screw_longer_than(foot_thickness(type) + t + 2 * washer_thickness(washer) + nut_thickness(nut, true) - squeeze); vflip() explode(15, true) { - color(pp4_colour) foot(type); + stl_colour(pp4_colour) foot(type); if(t) explode(15, true) @@ -136,7 +136,7 @@ assembly("insert_foot") { insert = screw_insert(screw); vflip() - color(pp1_colour) insert_foot(type); + stl_colour(pp4_colour) insert_foot(type); translate_z(-foot_thickness(type)) insert(insert); diff --git a/printed/handle.scad b/printed/handle.scad index 5077329..53bfb38 100644 --- a/printed/handle.scad +++ b/printed/handle.scad @@ -83,7 +83,7 @@ module handle_stl() { //! generate the STL module handle_assembly() pose([225, 0, 150], [0, 0, 14]) //! Printed part with inserts in place assembly("handle") { translate_z(handle_height()) - color(pp1_colour) vflip() handle_stl(); + stl_colour(pp1_colour) vflip() handle_stl(); handle_screw_positions() vflip() diff --git a/printed/pcb_mount.scad b/printed/pcb_mount.scad index 23595bd..d6e3c64 100644 --- a/printed/pcb_mount.scad +++ b/printed/pcb_mount.scad @@ -101,7 +101,7 @@ module pcb_mount_assembly(pcb, thickness, height = 5) { //! A PCB mount assembly translate_z(height) pcb(pcb); - color(pp1_colour) pcb_mount(pcb, washers = false); + stl_colour(pp1_colour) pcb_mount(pcb, washers = false); washer = screw_washer(screw); nut = screw_nut(screw); @@ -110,7 +110,7 @@ module pcb_mount_assembly(pcb, thickness, height = 5) { //! A PCB mount assembly pcb_mount_screw_positions(pcb) { translate_z(height + t) { - color(pp2_colour) pcb_mount_washer_stl(); + stl_colour(pp2_colour) pcb_mount_washer_stl(); translate_z(washer_thickness) screw(screw, screw_length); diff --git a/printed/printed_box.scad b/printed/printed_box.scad index 0021a98..a9a1aae 100644 --- a/printed/printed_box.scad +++ b/printed/printed_box.scad @@ -221,7 +221,7 @@ module pbox_base_screws(type, thickness = 0) //! Place the screws and pbox_screw_positions(type) { foot = pbox_foot(type); if(foot) - color(pp4_colour) + stl_colour(pp4_colour) foot(foot); translate_z(foot ? foot_thickness(foot) : thickness) diff --git a/printed/psu_shroud.scad b/printed/psu_shroud.scad index 8c9d8cc..23732f7 100644 --- a/printed/psu_shroud.scad +++ b/printed/psu_shroud.scad @@ -147,7 +147,7 @@ assembly(str("PSU_shroud_", name)) { translate_z(psu_shroud_height(type)) vflip() - color(pp1_colour) psu_shroud(type, cable_d, name, cables); + stl_colour(pp1_colour) psu_shroud(type, cable_d, name, cables); psu_shroud_hole_positions(type) vflip() diff --git a/printed/ribbon_clamp.scad b/printed/ribbon_clamp.scad index eea8b92..127727d 100644 --- a/printed/ribbon_clamp.scad +++ b/printed/ribbon_clamp.scad @@ -83,7 +83,7 @@ module ribbon_clamp_assembly(ways) pose([55, 180, 25]) //! Printed part with in assembly(str("ribbon_clamp_", ways)) { h = ribbon_clamp_height(); - color(pp1_colour) render() + stl_colour(pp1_colour) render() translate_z(h) vflip() ribbon_clamp(ways); ribbon_clamp_hole_positions(ways) @@ -103,7 +103,7 @@ module ribbon_clamp_fastened_assembly(ways, thickness, screw = screw) { //! Clam ribbon_clamp_assembly(ways); - color("red") translate_z(tape_thickness / 2) + stl_colour("red") translate_z(tape_thickness / 2) cube([tape_l, tape_width, tape_thickness], center = true); ribbon_clamp_hole_positions(ways) diff --git a/printed/screw_knob.scad b/printed/screw_knob.scad index 9443524..19a06e7 100644 --- a/printed/screw_knob.scad +++ b/printed/screw_knob.scad @@ -62,7 +62,7 @@ module screw_knob_assembly(screw, length) //! Assembly with the screw in place assembly(str("screw_knob_M", 20 * screw_radius(screw), "_", length)) { translate_z(knob_height) vflip() - color(pp1_colour) screw_knob(screw); + stl_colour(pp1_colour) screw_knob(screw); translate_z(knob_height - knob_nut_trap_depth(screw)) rotate(-45) diff --git a/printed/socket_box.scad b/printed/socket_box.scad index 39a2a96..72e785c 100644 --- a/printed/socket_box.scad +++ b/printed/socket_box.scad @@ -92,7 +92,7 @@ assembly(str("socket_box_", type[0])) { screw = mains_socket_screw(type); insert = screw_insert(screw); - color(pp1_colour) render() socket_box(type); + stl_colour(pp1_colour) render() socket_box(type); mains_socket_hole_positions(type) translate_z(height) diff --git a/printed/ssr_shroud.scad b/printed/ssr_shroud.scad index 5fc0d52..d647035 100644 --- a/printed/ssr_shroud.scad +++ b/printed/ssr_shroud.scad @@ -111,7 +111,7 @@ assembly(str("SSR_shroud_", name)) { translate_z(ssr_shroud_height(type)) vflip() - color(pp1_colour) ssr_shroud(type, cable_d, name); + stl_colour(pp1_colour) ssr_shroud(type, cable_d, name); ssr_shroud_hole_positions(type) insert(insert); @@ -135,7 +135,7 @@ module ssr_shroud_fastened_assembly(type, cable_d, thickness, name) //! Assembly *translate_z(cable_d / 2) rotate([90, 0, 0]) - color(grey20) + stl_colour(grey20) cylinder(d = cable_d, h = 20, center = true); } } diff --git a/printed/strap_handle.scad b/printed/strap_handle.scad index b5bab81..2404a60 100644 --- a/printed/strap_handle.scad +++ b/printed/strap_handle.scad @@ -160,7 +160,7 @@ module strap_end(type = strap) { //! Generate the STL for end piece // module strap_end_assembly(type = strap) assembly("strap_end") { - color(pp1_colour) + stl_colour(pp1_colour) strap_end(type); translate_z(strap_height(type) + strap_key(type)) @@ -175,7 +175,7 @@ module strap_assembly(length, type = strap) { //! Assembly with screws in place screw_length = screw_shorter_than(washer_thickness(washer) + washer_thickness(penny) + insert_length(insert) + panel_clearance + counterbore); - color(pp4_colour) strap(length, type); + stl_colour(pp4_colour) strap(length, type); strap_screw_positions(length, type) translate_z(strap_height(type)) diff --git a/readme.md b/readme.md index 035fe36..6eb6774 100644 --- a/readme.md +++ b/readme.md @@ -5209,6 +5209,7 @@ The resulting flat BOM is shown but heirachical BOMs are also generated for real | ```pose_hflip(exploded = undef)``` | Pose an STL or assembly for rendering to png by flipping around the Y axis, ```exploded = true for``` just the exploded view or ```false``` for unexploded only. | | ```pose_vflip(exploded = undef)``` | Pose an STL or assembly for rendering to png by flipping around the X axis, ```exploded = true for``` just the exploded view or ```false``` for unexploded only. | | ```stl(name)``` | Name an stl that will appear on the BOM, there needs to a module named ```_stl``` to make it | +| ```stl_colour(colour)``` | Colour an stl where it is placed in an assembly | | ```vitamin(description)``` | Describe a vitamin for the BOM entry and precede it with a module call that creates it, eg. "wigit(42): Type 42 widget" | ![bom](tests/png/bom.png) diff --git a/scripts/bom.py b/scripts/bom.py index e69b8cc..ee27d30 100755 --- a/scripts/bom.py +++ b/scripts/bom.py @@ -46,6 +46,16 @@ def find_scad_file(mname): return filename return None +class Part: + def __init__(self, args): + self.count = 1 + for arg in args: + arg = arg.replace('true', 'True').replace('false', 'False').replace('undef', 'None') + exec('self.' + arg) + + def data(self): + return self.__dict__ + class BOM: def __init__(self, name): self.name = name @@ -65,12 +75,17 @@ class BOM: "big" : self.big, "count" : self.count, "assemblies" : assemblies, - "vitamins" : self.vitamins, - "printed" : self.printed, - "routed" : self.routed + "vitamins" : {v : self.vitamins[v].data() for v in self.vitamins}, + "printed" : {p : self.printed[p].data() for p in self.printed}, + "routed" : {r : self.routed[r].data() for r in self.routed} } def add_part(self, s): + args = [] + match = re.match(r'^(.*?\.stl)\((.*)\)$', s) #look for name.stl(...) + if match: + s = match.group(1) + args = [match.group(2)] if s[-4:] == ".stl": parts = self.printed else: @@ -79,9 +94,9 @@ class BOM: else: parts = self.vitamins if s in parts: - parts[s] += 1 + parts[s].count += 1 else: - parts[s] = 1 + parts[s] = Part(args) def add_assembly(self, ass, args = []): if ass in self.assemblies: @@ -126,10 +141,10 @@ class BOM: for ass in sorted(self.assemblies): bom = self.assemblies[ass] if part in bom.vitamins: - file.write("%2d|" % bom.vitamins[part]) + file.write("%2d|" % bom.vitamins[part].count) else: file.write(" |") - print("%3d" % self.vitamins[part], description, file=file) + print("%3d" % self.vitamins[part].count, description, file=file) if self.printed: if self.vitamins: @@ -140,10 +155,10 @@ class BOM: for ass in sorted(self.assemblies): bom = self.assemblies[ass] if part in bom.printed: - file.write("%2d|" % bom.printed[part]) + file.write("%2d|" % bom.printed[part].count) else: file.write(" |") - print("%3d" % self.printed[part], part, file=file) + print("%3d" % self.printed[part].count, part, file=file) if self.routed: print(file=file) @@ -153,10 +168,10 @@ class BOM: for ass in sorted(self.assemblies): bom = self.assemblies[ass] if part in bom.routed: - file.write("%2d|" % bom.routed[part]) + file.write("%2d|" % bom.routed[part].count) else: file.write(" |") - print("%3d" % self.routed[part], part, file=file) + print("%3d" % self.routed[part].count, part, file=file) if self.assemblies: print(file=file) diff --git a/scripts/render.py b/scripts/render.py index 266b8e2..160551e 100755 --- a/scripts/render.py +++ b/scripts/render.py @@ -29,6 +29,7 @@ import openscad from tests import do_cmd, update_image, colour_scheme, background from deps import mtime from colorama import init +import json def usage(): print("\nusage:\n\trender [target_config] - Render images of the stl and dxf files."); @@ -48,6 +49,20 @@ def render(target, type): # parts = bom_to_parts(bom_dir, type) # + # Read the json bom to get the colours + # + bom_file = bom_dir + "/bom.json" + with open(bom_file) as json_file: + flat_bom = json.load(json_file) + + things = { 'stl' : 'printed', 'dxf' : 'routed' }[type] + colours = {} + for ass in flat_bom: + for part in ass[things]: + obj = ass[things][part] + if "colour" in obj: + colours[part] = obj["colour"] + # # Remove unused png files # for file in os.listdir(target_dir): @@ -55,7 +70,9 @@ def render(target, type): if not file[:-4] + '.' + type in parts: print("Removing %s" % file) os.remove(target_dir + '/' + file) - + # + # Render the parts + # for part in parts: part_file = target_dir + '/' + part png_name = target_dir + '/' + part[:-4] + '.png' @@ -64,8 +81,13 @@ def render(target, type): # if mtime(part_file) > mtime(png_name): png_maker_name = "png.scad" + colour = [0, 146/255, 0] + if part in colours: + colour = colours[part] + if not '[' in colour: + colour = '"' + colour + '"' with open(png_maker_name, "w") as f: - f.write('color([0, 146/255, 0]) import("%s");\n' % part_file) + f.write('color(%s) import("%s");\n' % (colour, part_file)) cam = "--camera=0,0,0,70,0,315,500" if type == 'stl' else "--camera=0,0,0,0,0,0,500" render = "--preview" if type == 'stl' else "--render" tmp_name = 'tmp.png' diff --git a/scripts/tests.py b/scripts/tests.py index 14676d0..3590b94 100755 --- a/scripts/tests.py +++ b/scripts/tests.py @@ -232,9 +232,10 @@ def tests(tests): j = name.find(']]') + 2 name = name.replace(name[i : j], '[ ... ]') desc = vit[1] - body += ['| %3d | %s | %s |' % (things[item], name, desc)] + body += ['| %3d | %s | %s |' % (things[item]["count"], name, desc)] else: - body += ['| %3d | %s |' % (things[item], name)] + count = things[item] if thing == 'assemblies' else things[item]["count"] + body += ['| %3d | %s |' % (count, name)] body += [''] body += ['\nTop'] diff --git a/scripts/views.py b/scripts/views.py index 7770a40..d9b49e7 100755 --- a/scripts/views.py +++ b/scripts/views.py @@ -248,9 +248,9 @@ def views(target, do_assemblies = None): for t in types: for thing in ass[t]: if thing in things[t]: - things[t][thing] += ass[t][thing] + things[t][thing] += ass[t][thing]["count"] else: - things[t][thing] = ass[t][thing] + things[t][thing] = ass[t][thing]["count"] for ass in flat_bom: name = titalise(ass["name"][:-9]).replace(' ',' ') print('| %s ' % name, file = doc_file, end = '') @@ -265,7 +265,7 @@ def views(target, do_assemblies = None): 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 + count = ass[t][thing]["count"] 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: @@ -301,7 +301,7 @@ def views(target, do_assemblies = None): print("|Qty|Description|", file = doc_file) print("|---:|:----------|", file = doc_file) for v in sorted(vitamins, key = lambda s: s.split(":")[-1]): - print("|%d|%s|" % (vitamins[v], v.split(":")[1]), file = doc_file) + print("|%d|%s|" % (vitamins[v]["count"], v.split(":")[1]), file = doc_file) print("\n", file = doc_file) printed = ass["printed"] @@ -310,7 +310,7 @@ def views(target, do_assemblies = None): keys = sorted(list(printed.keys())) for i in range(len(keys)): p = keys[i] - print('%s %d x %s |' % ('\n|' if not (i % 3) else '', printed[p], p), file = doc_file, end = '') + print('%s %d x %s |' % ('\n|' if not (i % 3) else '', printed[p]["count"], p), file = doc_file, end = '') if (i % 3) == 2 or i == len(printed) - 1: n = (i % 3) + 1 print('\n|%s' % ('---|' * n), file = doc_file) @@ -326,7 +326,7 @@ def views(target, do_assemblies = None): keys = sorted(list(routed.keys())) for i in range(len(keys)): r = keys[i] - print('%s %d x %s |' % ('\n|' if not (i % 3) else '', routed[r], r), file = doc_file, end = '') + print('%s %d x %s |' % ('\n|' if not (i % 3) else '', routed[r]["count"], r), file = doc_file, end = '') if (i % 3) == 2 or i == len(routed) - 1: n = (i % 3) + 1 print('\n|%s' % ('---|' * n), file = doc_file) diff --git a/tests/png/foot.png b/tests/png/foot.png index ba38b1b..99594ac 100644 Binary files a/tests/png/foot.png and b/tests/png/foot.png differ diff --git a/utils/core/bom.scad b/utils/core/bom.scad index 22ee941..1886a74 100644 --- a/utils/core/bom.scad +++ b/utils/core/bom.scad @@ -101,9 +101,17 @@ module assembly(name, big = undef) { //! Name an assembly that will appear on echo(str("~}", name, "_assembly")); } -module stl(name) { //! Name an stl that will appear on the BOM, there needs to a module named ```_stl``` to make it - if(bom_mode()) - echo(str("~", name, ".stl")); +module stl_colour(colour) { //! Colour an stl where it is placed in an assembly + $stl_colour = colour; + color(colour) + children(); +} + +module stl(name) { //! Name an stl that will appear on the BOM, there needs to a module named ```_stl``` to make it + if(bom_mode()) { + colour = is_undef($stl_colour) ? pp1_colour : $stl_colour; + echo(str("~", name, ".stl(colour='", colour, "')")); + } } module dxf(name) { //! Name a dxf that will appear on the BOM, there needs to a module named ```_dxf``` to make it