cad_models/fridge_shelf.py

96 lines
3.2 KiB
Python
Raw Permalink Normal View History

# /// script
# requires-python = ">=3.14"
# dependencies = ["ocp_vscode", "build123d"]
# ///
from build123d import *
from ocp_vscode import *
### Dimensions ###
total_length = (11.0 + 7.0 / 8.0) * IN
width = (4.0 + 3.0 / 4.0) * IN
thickness = 0.5 * IN
slot_height = (3.0 / 8.0) * IN
slot_thickness = 1.0 / 4.0 * IN
slot_width = (1.0 + 3.0 / 8.0) * IN - 2 * slot_thickness
slot_axial_thickness = 0.1 * IN
step_height = 3.0 / 32.0 * IN
step_width = 2.75 * IN
tab_size = 1 * IN
##################
class ShelfHalf(Compound):
def __init__(self, width, length, thickness, right):
with BuildPart() as half:
with BuildSketch() as sketch:
Rectangle(length, width)
extrude(amount=thickness)
with BuildSketch(half.faces().sort_by(Axis.Z)[0]) as sketch:
with Locations((0, width / 2.0)):
Rectangle(length, step_width, align=(Align.CENTER, Align.MAX))
extrude(amount=step_height)
with BuildSketch(Plane.YZ.offset(-length / 2.0 if right else length / 2.0)):
z_align = Align.MAX
with Locations((-width / 2.0, 0)):
Rectangle(
slot_width + 2 * slot_thickness,
slot_height + slot_thickness,
align=(Align.MIN, z_align),
)
with Locations((slot_thickness - width / 2.0, 0)):
Rectangle(
slot_width,
slot_height,
align=(Align.MIN, z_align),
mode=Mode.SUBTRACT,
)
direction = 1 if right else -1
extrude(amount=slot_axial_thickness * direction)
fillet(
half.edges().filter_by(Axis.X),
radius=slot_width / 20.0,
)
if right:
loc_mul = 1.0
x_align = Align.MIN
extrude_mode = Mode.ADD
tolerance = 0
else:
loc_mul = -1.0
x_align = Align.MIN
extrude_mode = Mode.SUBTRACT
tolerance = 0.01
with BuildSketch(Plane.XY.offset(thickness)) as sketch:
with Locations(
(
loc_mul * length / 2.0,
0,
),
):
with GridLocations(0, width / 3.0, 1, 3):
Rectangle(
tab_size + tolerance,
tab_size + tolerance,
align=(x_align, Align.CENTER),
)
extrude(amount=-thickness / 2.0, mode=extrude_mode)
RigidJoint(
"face_joint", joint_location=Location((loc_mul * length / 2.0, 0))
)
super().__init__(half.part.wrapped, joints=half.part.joints)
right = ShelfHalf(width, total_length / 2.0, thickness, True)
left = ShelfHalf(width, total_length / 2.0, thickness, False)
left.joints["face_joint"].connect_to(right.joints["face_joint"])
show(right, left)
export_stl(right, "right_shelf.stl")
export_stl(left, "left_shelf.stl")