87 lines
3.3 KiB
Python
87 lines
3.3 KiB
Python
from ocp_vscode import *
|
|
from build123d import *
|
|
from math import sqrt, atan, pi, cos, radians
|
|
|
|
class HingeProfile(BaseSketchObject):
|
|
def __init__(
|
|
self,
|
|
height: float,
|
|
width: float,
|
|
thickness: float = 0.5*MM,
|
|
radius: float = 0.25 * MM,
|
|
rotation: float = 0,
|
|
align: tuple[Align, Align] = (Align.CENTER, Align.CENTER),
|
|
mode: Mode = Mode.ADD,
|
|
):
|
|
circle = Pos(0, (thickness/2 + radius)) * Circle(radius)
|
|
line_1 = PointArcTangentLine(( width/2, height/2), circle.edge())
|
|
line_2 = PointArcTangentLine((-width/2, height/2), circle.edge(), Side.RIGHT)
|
|
|
|
lines = Curve() + [
|
|
Line((width/2, height/2), (width/2, 0)),
|
|
line_1,
|
|
RadiusArc(line_1.end_point(), line_2.end_point(), radius),
|
|
line_2,
|
|
Line((-width/2, height/2), (-width/2, 0)),
|
|
Line((-width/2, 0), (width/2, 0)),
|
|
]
|
|
|
|
hinge_profile = make_face(lines)
|
|
hinge_profile += mirror(hinge_profile)
|
|
super().__init__(obj=make_face(hinge_profile), rotation=rotation, align=align, mode=mode)
|
|
|
|
class Pack(BasePartObject):
|
|
def __init__(
|
|
self,
|
|
card_x: float = 69.5 * MM,
|
|
card_y: float = 95 * MM,
|
|
card_t: float = (0.3+2*0.04+2*0.12) * MM,
|
|
card_num: int = 15,
|
|
fit: float = 1 * MM,
|
|
wall: float = 2 * MM,
|
|
magnet_d: float = 10 * MM,
|
|
magnet_t: float = 1 * MM,
|
|
hinge_thickness: float = 0.5 * MM,
|
|
hinge_radius: float = 0.25 * MM,
|
|
rotation: float = (0, 0, 0),
|
|
align: tuple[Align, Align] = (Align.CENTER, Align.CENTER),
|
|
mode: Mode = Mode.ADD,
|
|
):
|
|
x = card_x + fit
|
|
y = card_y + fit
|
|
z = card_t*card_num + fit
|
|
s = wall
|
|
profile = Rectangle(x, y)
|
|
|
|
for i in [-1, 1]:
|
|
profile += Pos(0, i*(y/2 + s + z/2)) * Rectangle(x, z)
|
|
profile += Pos(0, i*(y/2 + y/8 + 2*s + z)) * Rectangle(x, y/4)
|
|
profile += Pos(i*(x/2 + s + z/2 + wall/2), 0) * Rectangle(z + wall, y)
|
|
profile += Pos(i*(3*x/4 + 2*s + z + wall), 0) * Rectangle(x/2, y)
|
|
|
|
part = extrude(profile, wall)
|
|
hinge = HingeProfile(s, wall, hinge_thickness, hinge_radius, (90, 0, 0), align=(Align.CENTER, Align.MIN))
|
|
|
|
for i in [-1, 1]:
|
|
part += extrude(Pos(i*(x/2+s/2), -y/2) * hinge, y, (0, 1, 0))
|
|
part += extrude(Pos(i*(x/2+3*s/2+z+wall), -y/2) * hinge, y, (0, 1, 0))
|
|
part += extrude(Pos(-x/2, i*(y/2+s/2)) * Rot(0, 0, 90) * hinge, x, (1, 0, 0))
|
|
part += extrude(Pos(-x/2, i*(y/2+3*s/2+z)) * Rot(0, 0, 90) * hinge, x, (1, 0, 0))
|
|
|
|
magnet_hole = extrude(Pos(0, 0, (wall-magnet_t)/2) * Circle(magnet_d/2), magnet_t)
|
|
|
|
for i in [-1, 1]:
|
|
for j in [-1, 1]:
|
|
part -= Pos(j*x/4, i*(y/2 + 2*s + z + y/8)) * magnet_hole
|
|
part -= Pos(j*(x/2 + 2*s + wall + z + x/4), i*(y/2 - y/8)) * magnet_hole
|
|
|
|
super().__init__(part=part, rotation=rotation, align=align, mode=mode)
|
|
|
|
|
|
pack_superthin = Pack(wall=1*MM, hinge_thickness=0.25*MM, hinge_radius=0.2*MM)
|
|
export_stl(pack_superthin, "pack_superthin.stl")
|
|
show(pack_superthin)
|
|
|
|
pack = Pack()
|
|
export_stl(pack, "pack.stl")
|
|
show(pack) |