commeownder/case/case.py

62 lines
1.9 KiB
Python

from build123d import *
# --- Facade panel ---
PANEL = 1.6 # plate thickness (Cherry MX standard ~1.5 mm)
# --- Component footprints ---
SW_SIZE = 14.0 # Cherry MX plate cutout (square)
SW_PITCH = 19.0 # switch centre-to-centre
N_SW = 3
OLED_W = 25.0 # 0.96" SSD1306 visible window width
OLED_H = 13.0 # visible window height
# --- OLED alignment pegs (solid 2 mm, 24 mm square pattern) ---
POST_D = 2.0 # peg diameter
POST_SPACING = 24.0 # hole centre-to-centre
POST_H = 12.0 # peg length behind panel
# --- Layout ---
# MARGIN_Y=7 and OLED_SW_GAP=9 push outer_h to 50 mm, giving the top pegs
# 1.5 mm clearance from the panel edge and the bottom pegs 2.5 mm clearance
# above the switch cutout tops.
MARGIN_X = 3.0
MARGIN_Y = 7.0
OLED_SW_GAP = 9.0
outer_w = (N_SW - 1) * SW_PITCH + SW_SIZE + 2 * MARGIN_X # 58 mm
outer_h = 2 * MARGIN_Y + OLED_H + OLED_SW_GAP + SW_SIZE # 50 mm
oled_cy = outer_h / 2 - MARGIN_Y - OLED_H / 2 # 11.5 mm
sw_cy = -outer_h / 2 + MARGIN_Y + SW_SIZE / 2 # -11.0 mm
with BuildPart() as case:
Box(outer_w, outer_h, PANEL)
with BuildSketch(Plane.XY.offset(PANEL / 2)):
with Locations((0, oled_cy)):
Rectangle(OLED_W, OLED_H)
with Locations((-SW_PITCH, sw_cy), (0, sw_cy), (SW_PITCH, sw_cy)):
RectangleRounded(SW_SIZE, SW_SIZE, 0.3)
extrude(amount=-PANEL, mode=Mode.SUBTRACT)
# Solid 2 mm alignment pegs extending from the back face
half_s = POST_SPACING / 2
post_z = -PANEL / 2 - POST_H / 2
post_xy = [
(-half_s, oled_cy - half_s),
( half_s, oled_cy - half_s),
(-half_s, oled_cy + half_s),
( half_s, oled_cy + half_s),
]
with Locations([(x, y, post_z) for x, y in post_xy]):
Cylinder(POST_D / 2, POST_H)
export_stl(case.part, "case/output/case.stl")
try:
from ocp_vscode import show
show(case)
except Exception:
pass