from build123d import * # --- Facade panel --- PANEL = 1.5 # plate thickness (Cherry MX standard ~1.5 mm) OLED_GLASS_X = 27 OLED_GLASS_Y = 19.5 OLED_GLASS_IN = 1.0 # --- 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_X = 23.0 # hole centre-to-centre POST_SPACING_Y = 23.6 POST_OFFSET = 4.35 # offset between hole and screen POST_H = 3.0 # peg length behind panel inner_w = OLED_W + 25 inner_h = OLED_H + 25 inner_z = 22.5 oled_x = 0 oled_y = 0 with BuildPart() as case: with Locations((0, 0, PANEL/2)): Box(inner_w+2*PANEL, inner_h+2*PANEL, PANEL) with BuildSketch(Plane.XY): with Locations((oled_x, oled_y)): Rectangle(OLED_W, OLED_H) extrude(amount=PANEL, mode=Mode.SUBTRACT) with BuildSketch(Plane.XY.offset(PANEL-OLED_GLASS_IN)): with Locations((oled_x, oled_y+POST_OFFSET/2)): Rectangle(OLED_GLASS_X, OLED_GLASS_Y) extrude(amount=OLED_GLASS_IN, mode=Mode.SUBTRACT) with Locations((0, inner_h/2+PANEL/2, inner_z/2+PANEL)): Box(inner_w+2*PANEL, PANEL, inner_z+2*PANEL) with Locations((0, -inner_h/2-PANEL/2, inner_z/2+PANEL)): Box(inner_w+2*PANEL, PANEL, inner_z+2*PANEL) with BuildSketch(Plane.XZ.offset(-inner_h/2)): with Locations((-SW_PITCH/2, PANEL+inner_z/2), (SW_PITCH/2, PANEL+inner_z/2)): RectangleRounded(SW_SIZE, SW_SIZE, 0.3) extrude(amount=-PANEL, mode=Mode.SUBTRACT) with Locations((-inner_w/2-PANEL/2, 0, inner_z/2+PANEL)): Box(PANEL, inner_h+2*PANEL, inner_z+2*PANEL) with Locations((inner_w/2+PANEL/2, 0, inner_z/2+PANEL)): Box(PANEL, inner_h+2*PANEL, inner_z+2*PANEL) with BuildSketch(Plane.YZ.offset(-inner_w/2)): with Locations((-SW_PITCH/2, PANEL+inner_z/2), (SW_PITCH/2, PANEL+inner_z/2)): RectangleRounded(SW_SIZE, SW_SIZE, 0.3) extrude(amount=-PANEL, mode=Mode.SUBTRACT) # Solid 2 mm alignment pegs extending from the back face half_x = POST_SPACING_X / 2 half_y = POST_SPACING_Y / 2 post_xy = [ (-half_x, half_y + POST_OFFSET/2), ( half_x,-half_y + POST_OFFSET/2), (-half_x,-half_y + POST_OFFSET/2), ( half_x, half_y + POST_OFFSET/2), ] with Locations([(x + oled_x, y + oled_y, POST_H/2 + PANEL) for x, y in post_xy]): Cylinder(POST_D / 2, POST_H) export_stl(case.part, "case.stl") try: from ocp_vscode import show show(case) except Exception: pass