From 0b6825491b0456cb1fef03015cf0824e4aaac760 Mon Sep 17 00:00:00 2001 From: Michael Przybilski Date: Fri, 2 Aug 2024 15:25:35 +0300 Subject: [PATCH 1/5] first draft --- build123d/anchor.py | 60 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 build123d/anchor.py diff --git a/build123d/anchor.py b/build123d/anchor.py new file mode 100644 index 0000000..4ae73c2 --- /dev/null +++ b/build123d/anchor.py @@ -0,0 +1,60 @@ +from build123d import ( + BuildPart, BuildSketch, BuildLine, Box, Plane, Polyline, Rectangle, Location, Locations, + Axis, Rot, Mode, Align, Until, + mirror, make_face, extrude, fillet, chamfer, split, faces, add, loft) + +try: + from ocp_vscode import show_object +except ModuleNotFoundError: + pass + +# top +TOP_WIDTH = 8 +TOP_PTS = ((0,4), + (11, 4), + (8, 8.3), + (0, 8.3), + (0, 4)) + +# bottom +BOTTOM_WIDTH = 7 +BOTTOM_PTS = ((6, 0), + (15, 0), + (11, 4), + (6, 4), + (6, 0)) + +BOTTOM_CUTOUT_WIDTH = 3 +BOTTOM_CUTOUT_PTS = ((6, 0), + (10, 0), + (6, 4), + (6, 0)) + + +with BuildPart() as anchor: + with BuildSketch(Plane.YZ): + with BuildLine(): + Polyline(TOP_PTS) + make_face() + extrude(amount=TOP_WIDTH) + + with BuildSketch(Plane.YZ.offset((TOP_WIDTH - BOTTOM_WIDTH) / 2)): + with BuildLine(): + Polyline(BOTTOM_PTS) + make_face() + extrude(amount=BOTTOM_WIDTH) + + with BuildPart(mode=Mode.SUBTRACT): + with BuildSketch(Plane.YZ.offset(TOP_WIDTH - BOTTOM_WIDTH + BOTTOM_CUTOUT_WIDTH / 2)): + with BuildLine(): + Polyline(BOTTOM_CUTOUT_PTS) + make_face() + extrude(amount=BOTTOM_CUTOUT_WIDTH) + + +# __main__ => show in VSCode +# temp => show in CQEditor +if __name__ in ['__main__', 'temp']: + if __name__ == '__main__': + from ocp_vscode import show_object + show_object(anchor) \ No newline at end of file From 72bee0d44b30aad29a93f0a9f8b990b1ffef6040 Mon Sep 17 00:00:00 2001 From: Michael Przybilski Date: Mon, 23 Sep 2024 11:39:02 +0300 Subject: [PATCH 2/5] Hex cutout, FDM bridge --- Makefile | 1 - build123d/anchor.py | 46 +++++++++++++++++++++++++++++++++------ build123d/wheel.py | 2 +- scripts/export_b123d.py | 5 +++++ scripts/export_blender.py | 1 - 5 files changed, 45 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 60041ab..cc71946 100644 --- a/Makefile +++ b/Makefile @@ -26,7 +26,6 @@ blend: $(BLENDER) blender/case_back.blend --background --python scripts/export_blender.py $(BLENDER) blender/trigger_R2.blend --background --python scripts/export_blender.py $(BLENDER) blender/trigger_R4.blend --background --python scripts/export_blender.py - $(BLENDER) blender/anchor.blend --background --python scripts/export_blender.py $(BLENDER) blender/dhat.blend --background --python scripts/export_blender.py $(BLENDER) blender/button_abxy.blend --background --python scripts/export_blender.py $(BLENDER) blender/button_dpad.blend --background --python scripts/export_blender.py diff --git a/build123d/anchor.py b/build123d/anchor.py index 4ae73c2..04cb892 100644 --- a/build123d/anchor.py +++ b/build123d/anchor.py @@ -1,7 +1,8 @@ from build123d import ( BuildPart, BuildSketch, BuildLine, Box, Plane, Polyline, Rectangle, Location, Locations, - Axis, Rot, Mode, Align, Until, - mirror, make_face, extrude, fillet, chamfer, split, faces, add, loft) + Axis, Rot, Mode, Align, Until, Cylinder, RegularPolygon, + mirror, make_face, edges, extrude, fillet, chamfer, split, faces, add, loft) + try: from ocp_vscode import show_object @@ -10,18 +11,28 @@ # top TOP_WIDTH = 8 +TOP_DEPTH = 8 +TOP_HEIGHT = 8.3 TOP_PTS = ((0,4), (11, 4), - (8, 8.3), - (0, 8.3), + (TOP_DEPTH, TOP_HEIGHT), + (0, TOP_HEIGHT), (0, 4)) +CHAMFER = 1 + +NUT_THICKNESS = 2.3 # should be 1.75 according to https://www.engineersedge.com/hardware/standard_metric_hex_nuts_13728.htm +NUT_WIDTH = 5 # across flats for M2.5 x 0.45 +NUT_TOLERANCE = 0.181 + +BOLT_HOLE_RAD = 1.3 # bottom BOTTOM_WIDTH = 7 +BOTTOM_HEIGHT = 4 BOTTOM_PTS = ((6, 0), (15, 0), - (11, 4), - (6, 4), + (11, BOTTOM_HEIGHT), + (6, BOTTOM_HEIGHT), (6, 0)) BOTTOM_CUTOUT_WIDTH = 3 @@ -30,6 +41,8 @@ (6, 4), (6, 0)) +FDM_BRIDGE_THICKNESS = 0.2 # only for FDM printing, otherwise set to 0 + with BuildPart() as anchor: with BuildSketch(Plane.YZ): @@ -38,6 +51,10 @@ make_face() extrude(amount=TOP_WIDTH) + edge_list = edges().filter_by(Axis.Z) + chamfer(edge_list, CHAMFER) + + with BuildSketch(Plane.YZ.offset((TOP_WIDTH - BOTTOM_WIDTH) / 2)): with BuildLine(): Polyline(BOTTOM_PTS) @@ -51,10 +68,25 @@ make_face() extrude(amount=BOTTOM_CUTOUT_WIDTH) + with BuildSketch(Location((TOP_WIDTH / 2, TOP_DEPTH / 2, TOP_HEIGHT - NUT_THICKNESS))) as poly_sk: + RegularPolygon((NUT_WIDTH + NUT_TOLERANCE) / 2, 6) + extrude(amount=NUT_THICKNESS, mode=Mode.SUBTRACT) + + with Locations(Location((TOP_WIDTH / 2, TOP_DEPTH / 2, (TOP_HEIGHT + BOTTOM_HEIGHT) / 2))): + Cylinder(BOLT_HOLE_RAD, TOP_HEIGHT - BOTTOM_HEIGHT, mode=Mode.SUBTRACT) + + if FDM_BRIDGE_THICKNESS > 0: + with Locations(Location((TOP_WIDTH / 2, TOP_DEPTH / 2, (TOP_HEIGHT + BOTTOM_HEIGHT) / 2 - 0.25))): + Box(BOLT_HOLE_RAD * 2, (NUT_WIDTH + NUT_TOLERANCE), FDM_BRIDGE_THICKNESS, mode=Mode.SUBTRACT) + + # __main__ => show in VSCode # temp => show in CQEditor if __name__ in ['__main__', 'temp']: if __name__ == '__main__': from ocp_vscode import show_object - show_object(anchor) \ No newline at end of file + + show_object(anchor) + + print(f"Volume: {anchor.part.volume}") diff --git a/build123d/wheel.py b/build123d/wheel.py index fd9ae90..c3bfa36 100644 --- a/build123d/wheel.py +++ b/build123d/wheel.py @@ -19,7 +19,7 @@ # Core CORE_RADIUS = 8 -CORE_TOLERANCE = 0.1 +CORE_TOLERANCE = 0.12 RIGHT_PADDING_LEN = 1.8 RIGHT_PADDING_RADIUS = 2 HEX_DIAMETER = 2.05 # 2 millimeter + extra for better fit. diff --git a/scripts/export_b123d.py b/scripts/export_b123d.py index 52b497b..120348c 100644 --- a/scripts/export_b123d.py +++ b/scripts/export_b123d.py @@ -6,6 +6,8 @@ from wheel import wheel, core, holder from trigger_r1 import trigger_r1 from cover import cover +from anchor import anchor + STL_DIR = 'stl/' STEP_DIR = 'step/' @@ -25,3 +27,6 @@ def export(obj, filename): # Battery Cover. export(cover.part, 'secondary_015mm_cover') + +# Anchor. +export(anchor.part, 'any_015mm_anchors_2x') diff --git a/scripts/export_blender.py b/scripts/export_blender.py index fb7fcef..24c1ec4 100644 --- a/scripts/export_blender.py +++ b/scripts/export_blender.py @@ -135,7 +135,6 @@ def export(self): Entry('Home', 'secondary_007mm_home', rotate=True), Entry('Thumbstick', 'secondary_007mm_thumbstick', tolerance=True), Entry('Hexagon', 'conductive_015mm_hexagon', '-Z', tolerance=True), - Entry('Anchor', 'any_015mm_anchors_2x', '-Z', split=True), Entry('Soldering helper', 'any_020mm_solderstand', '-Z', merge=True), ] From e5623246e779b257a3567ebd4d277d5f1c484a2e Mon Sep 17 00:00:00 2001 From: Michael Przybilski Date: Mon, 23 Sep 2024 16:40:42 +0300 Subject: [PATCH 3/5] fixed nut-cutout size bug --- build123d/anchor.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build123d/anchor.py b/build123d/anchor.py index 04cb892..430c301 100644 --- a/build123d/anchor.py +++ b/build123d/anchor.py @@ -22,7 +22,7 @@ NUT_THICKNESS = 2.3 # should be 1.75 according to https://www.engineersedge.com/hardware/standard_metric_hex_nuts_13728.htm NUT_WIDTH = 5 # across flats for M2.5 x 0.45 -NUT_TOLERANCE = 0.181 +NUT_TOLERANCE = +0.181 BOLT_HOLE_RAD = 1.3 @@ -41,7 +41,7 @@ (6, 4), (6, 0)) -FDM_BRIDGE_THICKNESS = 0.2 # only for FDM printing, otherwise set to 0 +FDM_BRIDGE_THICKNESS = 0.2 # only for FDM printing, otherwise set to 0.0 with BuildPart() as anchor: @@ -69,7 +69,7 @@ extrude(amount=BOTTOM_CUTOUT_WIDTH) with BuildSketch(Location((TOP_WIDTH / 2, TOP_DEPTH / 2, TOP_HEIGHT - NUT_THICKNESS))) as poly_sk: - RegularPolygon((NUT_WIDTH + NUT_TOLERANCE) / 2, 6) + RegularPolygon((NUT_WIDTH + NUT_TOLERANCE) / 2, 6, major_radius=False) extrude(amount=NUT_THICKNESS, mode=Mode.SUBTRACT) with Locations(Location((TOP_WIDTH / 2, TOP_DEPTH / 2, (TOP_HEIGHT + BOTTOM_HEIGHT) / 2))): From cddb0d07465a3f6b11c65ab3fb5fd1852067513a Mon Sep 17 00:00:00 2001 From: Michael Przybilski Date: Mon, 23 Sep 2024 16:46:10 +0300 Subject: [PATCH 4/5] cleanup --- build123d/anchor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build123d/anchor.py b/build123d/anchor.py index 430c301..f6dd1b1 100644 --- a/build123d/anchor.py +++ b/build123d/anchor.py @@ -68,7 +68,7 @@ make_face() extrude(amount=BOTTOM_CUTOUT_WIDTH) - with BuildSketch(Location((TOP_WIDTH / 2, TOP_DEPTH / 2, TOP_HEIGHT - NUT_THICKNESS))) as poly_sk: + with BuildSketch(Location((TOP_WIDTH / 2, TOP_DEPTH / 2, TOP_HEIGHT - NUT_THICKNESS))): RegularPolygon((NUT_WIDTH + NUT_TOLERANCE) / 2, 6, major_radius=False) extrude(amount=NUT_THICKNESS, mode=Mode.SUBTRACT) From 2a44f5a62b816cea9aa43ffec718c8a2951b1b49 Mon Sep 17 00:00:00 2001 From: Michael Przybilski Date: Tue, 24 Sep 2024 14:05:11 +0300 Subject: [PATCH 5/5] addressed comments --- build123d/anchor.py | 51 +++++++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 18 deletions(-) diff --git a/build123d/anchor.py b/build123d/anchor.py index f6dd1b1..66fcb56 100644 --- a/build123d/anchor.py +++ b/build123d/anchor.py @@ -4,11 +4,6 @@ mirror, make_face, edges, extrude, fillet, chamfer, split, faces, add, loft) -try: - from ocp_vscode import show_object -except ModuleNotFoundError: - pass - # top TOP_WIDTH = 8 TOP_DEPTH = 8 @@ -24,7 +19,7 @@ NUT_WIDTH = 5 # across flats for M2.5 x 0.45 NUT_TOLERANCE = +0.181 -BOLT_HOLE_RAD = 1.3 +BOLT_HOLE_RADIUS = 1.3 # bottom BOTTOM_WIDTH = 7 @@ -45,6 +40,7 @@ with BuildPart() as anchor: + #Top with BuildSketch(Plane.YZ): with BuildLine(): Polyline(TOP_PTS) @@ -54,30 +50,49 @@ edge_list = edges().filter_by(Axis.Z) chamfer(edge_list, CHAMFER) + # Remove cutout for nut + location = Location((TOP_WIDTH / 2, # align center + TOP_DEPTH / 2, # align center + TOP_HEIGHT - NUT_THICKNESS)) + with BuildSketch(location): + RegularPolygon((NUT_WIDTH + NUT_TOLERANCE) / 2, 6, major_radius=False) + extrude(amount=NUT_THICKNESS, mode=Mode.SUBTRACT) - with BuildSketch(Plane.YZ.offset((TOP_WIDTH - BOTTOM_WIDTH) / 2)): + # Remove cutout for bolt + location = Location((TOP_WIDTH / 2, # align center + TOP_DEPTH / 2, # align center + (TOP_HEIGHT + BOTTOM_HEIGHT) / 2)) + with Locations(location): + Cylinder(BOLT_HOLE_RADIUS, TOP_HEIGHT - BOTTOM_HEIGHT, mode=Mode.SUBTRACT) + + # Additional cutout to generate bridge for FDP printing + if FDM_BRIDGE_THICKNESS > 0: + location = Location((TOP_WIDTH / 2, # align center + TOP_DEPTH / 2, # align center + (TOP_HEIGHT + BOTTOM_HEIGHT) / 2 - FDM_BRIDGE_THICKNESS)) + with Locations(location): + Box(BOLT_HOLE_RADIUS * 2, + NUT_WIDTH + NUT_TOLERANCE, + FDM_BRIDGE_THICKNESS, + mode=Mode.SUBTRACT) + + + # Bottom + plane = Plane.YZ.offset((TOP_WIDTH - BOTTOM_WIDTH) / 2) + with BuildSketch(plane): with BuildLine(): Polyline(BOTTOM_PTS) make_face() extrude(amount=BOTTOM_WIDTH) with BuildPart(mode=Mode.SUBTRACT): - with BuildSketch(Plane.YZ.offset(TOP_WIDTH - BOTTOM_WIDTH + BOTTOM_CUTOUT_WIDTH / 2)): + plane = Plane.YZ.offset(TOP_WIDTH - BOTTOM_WIDTH + BOTTOM_CUTOUT_WIDTH / 2) + with BuildSketch(plane): with BuildLine(): Polyline(BOTTOM_CUTOUT_PTS) make_face() extrude(amount=BOTTOM_CUTOUT_WIDTH) - with BuildSketch(Location((TOP_WIDTH / 2, TOP_DEPTH / 2, TOP_HEIGHT - NUT_THICKNESS))): - RegularPolygon((NUT_WIDTH + NUT_TOLERANCE) / 2, 6, major_radius=False) - extrude(amount=NUT_THICKNESS, mode=Mode.SUBTRACT) - - with Locations(Location((TOP_WIDTH / 2, TOP_DEPTH / 2, (TOP_HEIGHT + BOTTOM_HEIGHT) / 2))): - Cylinder(BOLT_HOLE_RAD, TOP_HEIGHT - BOTTOM_HEIGHT, mode=Mode.SUBTRACT) - - if FDM_BRIDGE_THICKNESS > 0: - with Locations(Location((TOP_WIDTH / 2, TOP_DEPTH / 2, (TOP_HEIGHT + BOTTOM_HEIGHT) / 2 - 0.25))): - Box(BOLT_HOLE_RAD * 2, (NUT_WIDTH + NUT_TOLERANCE), FDM_BRIDGE_THICKNESS, mode=Mode.SUBTRACT)