2023-03-31 15:37:19 +00:00
|
|
|
import cadquery as cq
|
|
|
|
from cadquery import exporters
|
|
|
|
|
2023-04-15 20:38:43 +00:00
|
|
|
import dimensions as dim
|
|
|
|
from utils import extrude_shape2, hex_vents, punch_hole
|
2023-03-31 15:37:19 +00:00
|
|
|
|
|
|
|
# Dimensions for countersunk M4 screws
|
2023-04-03 17:16:20 +00:00
|
|
|
m4_top = 9
|
2023-03-31 15:37:19 +00:00
|
|
|
m4_bottom = 4
|
|
|
|
|
|
|
|
|
2023-03-31 15:56:51 +00:00
|
|
|
lip_thickness = 1.5
|
|
|
|
# Position of pillar + shell_t + pillar "radius" + lip
|
2023-04-15 20:38:43 +00:00
|
|
|
dim.height = (
|
|
|
|
max([y for _, y in dim.mounting_pillar_positions]) + 6 + dim.shell_t + lip_thickness
|
|
|
|
)
|
|
|
|
thickness = dim.shell_t
|
2023-03-31 15:37:19 +00:00
|
|
|
front_lip = 8
|
|
|
|
|
|
|
|
|
|
|
|
def model():
|
2023-04-04 19:18:32 +00:00
|
|
|
# Create the basic shape of the case lid
|
2023-03-31 15:37:19 +00:00
|
|
|
model = (
|
|
|
|
cq.Workplane("XY")
|
|
|
|
# Hollow box
|
2023-04-15 20:38:43 +00:00
|
|
|
.box(dim.width, dim.height, thickness)
|
2023-03-31 15:37:19 +00:00
|
|
|
.edges("|Z and >Y")
|
|
|
|
.fillet(2)
|
|
|
|
)
|
|
|
|
|
|
|
|
# Make many holes
|
2023-04-15 20:38:43 +00:00
|
|
|
vent = hex_vents(size=6, width=dim.width * 0.9, height=dim.height * 0.9)[0]
|
2023-03-31 15:37:19 +00:00
|
|
|
model = punch_hole(
|
|
|
|
model=model,
|
|
|
|
face=">Z",
|
2023-04-15 20:38:43 +00:00
|
|
|
w=dim.width,
|
|
|
|
h=dim.height,
|
|
|
|
x_offset=0.05 * dim.width,
|
|
|
|
y_offset=0.05 * dim.height,
|
2023-03-31 15:37:19 +00:00
|
|
|
hole=vent,
|
|
|
|
depth=thickness,
|
|
|
|
)
|
|
|
|
|
|
|
|
# Add screw holes
|
2023-04-15 20:38:43 +00:00
|
|
|
for position in dim.mounting_pillar_positions:
|
2023-03-31 15:37:19 +00:00
|
|
|
model = (
|
|
|
|
model.faces(">Z")
|
|
|
|
.workplane(centerOption="CenterOfBoundBox")
|
2023-04-15 20:38:43 +00:00
|
|
|
.center(
|
|
|
|
-dim.width / 2 + position[0], dim.height / 2 - position[1] - dim.shell_t
|
|
|
|
)
|
2023-04-03 17:16:20 +00:00
|
|
|
.placeSketch(cq.Sketch().circle(m4_top / 2 + 1.5))
|
2023-03-31 15:37:19 +00:00
|
|
|
.extrude(-thickness)
|
|
|
|
.faces(">Z")
|
|
|
|
.workplane(centerOption="CenterOfBoundBox")
|
2023-04-15 20:38:43 +00:00
|
|
|
.center(
|
|
|
|
-dim.width / 2 + position[0], dim.height / 2 - position[1] - dim.shell_t
|
|
|
|
)
|
2023-03-31 15:37:19 +00:00
|
|
|
.cskHole(m4_bottom, m4_top, 82, depth=None)
|
|
|
|
)
|
|
|
|
|
2023-03-31 15:56:51 +00:00
|
|
|
# Add front lip
|
2023-03-31 15:37:19 +00:00
|
|
|
|
|
|
|
model = (
|
|
|
|
model.faces(">Z")
|
|
|
|
.workplane(centerOption="CenterOfBoundBox")
|
2023-04-15 20:38:43 +00:00
|
|
|
.center(0, -dim.height / 2 + lip_thickness / 2)
|
|
|
|
.placeSketch(
|
|
|
|
cq.Sketch().trapezoid(dim.width - 2 * dim.shell_t, lip_thickness, 90)
|
|
|
|
)
|
2023-03-31 15:37:19 +00:00
|
|
|
.extrude(-front_lip - thickness)
|
|
|
|
)
|
|
|
|
|
|
|
|
return model
|
|
|
|
|
|
|
|
|
2023-04-04 13:43:06 +00:00
|
|
|
def decorative_cover():
|
2023-04-04 19:18:32 +00:00
|
|
|
# A decorative thingie to cover the ugly seam in the middle
|
2023-04-15 20:38:43 +00:00
|
|
|
model = cq.Workplane("XY").box(10, dim.height, 1).edges("|Z").fillet(1)
|
|
|
|
vent = hex_vents(
|
|
|
|
size=6, width=dim.width * 0.9, height=dim.height * 0.9, density=0.775
|
|
|
|
)[0]
|
2023-04-04 13:43:06 +00:00
|
|
|
|
|
|
|
model = extrude_shape2(
|
|
|
|
model=model,
|
|
|
|
face=">Z",
|
2023-04-15 20:38:43 +00:00
|
|
|
w=dim.width,
|
|
|
|
h=dim.height,
|
|
|
|
x_offset=0.05 * dim.width,
|
|
|
|
y_offset=0.05 * dim.height,
|
2023-04-04 13:43:06 +00:00
|
|
|
hole=vent,
|
|
|
|
depth=3,
|
|
|
|
)
|
|
|
|
return model
|
|
|
|
|
|
|
|
|
2023-03-31 15:37:19 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
model = model()
|
|
|
|
exporters.export(model, "lid.stl")
|
|
|
|
|
2023-04-04 13:43:06 +00:00
|
|
|
cover = decorative_cover()
|
|
|
|
exporters.export(cover, "lid_cover.stl")
|
|
|
|
|
2023-03-31 18:25:03 +00:00
|
|
|
exporters.export(
|
|
|
|
model,
|
|
|
|
"lid.svg",
|
|
|
|
opt={
|
|
|
|
"projectionDir": (0, 0, 1),
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
2023-03-31 15:37:19 +00:00
|
|
|
exporters.export(
|
2023-04-15 20:38:43 +00:00
|
|
|
model.faces(">X").workplane(offset=-dim.width / 2).split(keepTop=True),
|
2023-03-31 15:37:19 +00:00
|
|
|
"right_side_lid.stl",
|
|
|
|
)
|
|
|
|
exporters.export(
|
2023-04-15 20:38:43 +00:00
|
|
|
model.faces(">X").workplane(offset=-dim.width / 2).split(keepBottom=True),
|
2023-03-31 15:37:19 +00:00
|
|
|
"left_side_lid.stl",
|
|
|
|
)
|