From 5def2ff98fd8f3b305e3f53c103e8539baf88947 Mon Sep 17 00:00:00 2001 From: Noah Metz Date: Wed, 21 May 2025 00:59:50 -0600 Subject: [PATCH] Added multibin insert --- counters.py | 108 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 71 insertions(+), 37 deletions(-) diff --git a/counters.py b/counters.py index 3187ece..09e86c2 100644 --- a/counters.py +++ b/counters.py @@ -1,15 +1,13 @@ from ocp_vscode import * from build123d import * -from math import tan, pi, radians +from math import tan, sin, cos, sqrt, pi, radians def PG(x, y, angle): return Polygon((x, 0), (x, y), (0, y + x * tan(radians(angle))), (0, x * tan(radians(angle))), align=Align.MIN) def CounterVal(val): - if val > 0: + if val >= 0: return f"+{val}" - elif val < 0: - return f"-{val}" else: return f"{val}" @@ -42,13 +40,13 @@ def Numerical(left, right, x, y, t, angle, base_z, text_z): return counter -def Textual(text, image, image_yoff, x, y, t, angle, base_z, text_z): +def Textual(text, image, image_yoff, font_mul, x, y, t, angle, base_z, text_z): counter = extrude(Chevron(x, y, angle), base_z + text_z, (0, 0, 1)) counter -= extrude(Pos(0, t + t*tan(radians(angle)), base_z + text_z) * Chevron(x-2*t, y-2*t, angle), text_z, (0, 0, -1)) font = "Arial Rounded MT Bold" - font_size = x/8 - top = Pos(0, x/2*tan(radians(angle)) + 2*t) * Text(text, font_size, font=font, align=(Align.CENTER, Align.MIN)) + font_size = x/6 * font_mul + top = Pos(0, x/2*tan(radians(angle)) + t + 2*font_size/3) * Text(text, font_size, font=font, align=(Align.CENTER, Align.NONE)) svg = import_svg(image, align=(Align.CENTER, Align.MIN)) svg_max_x = max([x.bounding_box().max.X for x in svg.faces()]) @@ -65,14 +63,36 @@ def Textual(text, image, image_yoff, x, y, t, angle, base_z, text_z): return counter - x = 25 * MM y = 10 * MM t = 1 * MM base_z = 1 * MM -text_z = 1 * MM +text_z = 0.5 * MM angle = 22.5 +def Holder(x, y, angle): + fit = 1 * MM + spacing = 3 * MM + total_x = x + fit + cut_size = 85 * MM + top_cut = 5 * MM + max_depth = 30 * MM + part = import_step("multibin_insert_2_2_1.step") + insert_top = part.faces().sort_by(SortBy.AREA)[-1] + part -= extrude(insert_top, top_cut, (0, 0, -1)) + + cut_profile = Location((0, -cut_size/2, max_depth), (-90, 0, 0)) * Pos(0, -total_x/2*tan(radians(angle))) * Chevron(total_x, y + max_depth, angle) + cut_profile = Plane(insert_top) * cut_profile + + cuts = [(10, 2.5*y), (3, y), (1, y)] + for j, (num_cuts, depth) in enumerate(cuts): + cut_len = (cut_size-(num_cuts-1)*spacing)/num_cuts + for i in range(num_cuts): + part -= Pos((-1+j)*(total_x + spacing), i*cut_len + i*spacing, -depth) * extrude(cut_profile, cut_len) + + return part + + number_counters = [ (1, 1), (5, 5), @@ -89,38 +109,52 @@ number_counters = [ ] image_counters = { - "Deathtouch": 2, - "Doublestrike": 0, - "First Strike": 0, - "Flying": 0, - "Goad": 0, - "Haste": -3, - "Hexproof": 0, - "Indestructible": 0, - "Lifelink": -2, - "Lore": 0, - "Menace": -2, - "Reach": -3, - "Ringbearer": 2, - "Shield": -2, - "Stun": -2, - "Time": 0, - "Trample": 0, - "Vigilance": -1.5, - "Charge": 0, + "Deathtouch": (2, 0.9), + "Double Strike": (0, 0.8), + "First Strike": (0, 1), + "Goad": (0, 1), + "Flying": (2, 1), + "Haste": (-3, 1), + "Hexproof": (0, 1), + "Indestructible": (0, 0.8), + "Lifelink": (-2, 1), + "Lore": (0, 1), + "Menace": (-2, 1), + "Reach": (-3, 1), + "Ringbearer": (2, 1), + "Shield": (-2, 1), + "Stun": (-2, 1), + "Time": (0, 1), + "Trample": (0, 1), + "Vigilance": (-1.5, 1), + "Charge": (0, 1), } -if True: - for numbers in number_counters: - counter = Numerical(numbers[0], numbers[1], x, y, t, angle, base_z, text_z) +export = True +one = False +display_objects = [] +for idx, numbers in enumerate(number_counters): + counter = Numerical(numbers[0], numbers[1], x, y, t, angle, base_z, text_z) + display_objects.append(Pos((x + 1 * MM) * idx, 0) * counter) + if export: export_step(counter, f"step/counter_{NumStr(numbers[0])}_{NumStr(numbers[1])}.step") export_stl(counter, f"stl/counter_{NumStr(numbers[0])}_{NumStr(numbers[1])}.stl") + if one: + break - for text, y_off in image_counters.items(): - counter = Textual(text, f"svg/{text.lower().replace(' ', '')}.svg", y_off, x, 2.5*y, t, angle, base_z, text_z) +for idx, (text, (y_off, font_mul)) in enumerate(image_counters.items()): + counter = Textual(text, f"svg/{text.lower().replace(' ', '')}.svg", y_off, font_mul, x, 2.5*y, t, angle, base_z, text_z) + display_objects.append(Pos((x + 1 * MM) * idx, y + 1 * MM) * counter) + if export: export_step(counter, f"step/counter_{text.lower().replace(' ', '')}.step") export_stl(counter, f"stl/counter_{text.lower().replace(' ', '')}.stl") -else: - text = "Charge" - counter = Textual(text, f"svg/{text.lower().replace(' ', '')}.svg", image_counters[text], x, 2.5*y, t, angle, base_z, text_z) - show(counter) \ No newline at end of file + if one: + break + +holder = Holder(x, y, angle) +display_objects.append(Pos(0, 4*x) * holder) +if export: + export_stl(holder, "holder.stl") + export_step(holder, "holder.step") + +show(display_objects) \ No newline at end of file