2023-03-01 18:47:06 +00:00
|
|
|
import cadquery as cq
|
|
|
|
|
|
|
|
# TODO make API of extrude_shape and punch_hole more consistent
|
|
|
|
def extrude_shape(*, model, face, w, h, x_offset, y_offset, shape, height):
|
|
|
|
return (
|
|
|
|
model.faces(face)
|
|
|
|
.workplane(centerOption="CenterOfBoundBox")
|
|
|
|
.center(-w / 2 + x_offset, -h / 2 + y_offset)
|
|
|
|
.placeSketch(shape)
|
|
|
|
.extrude(height)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def punch_hole(*, model, face, w, h, x_offset, y_offset, hole, depth):
|
|
|
|
return (
|
|
|
|
model.faces(face)
|
|
|
|
.workplane(centerOption="CenterOfBoundBox")
|
|
|
|
.center(-w / 2 + x_offset + hole["x"], -h / 2 + y_offset + hole["y"])
|
|
|
|
.placeSketch(
|
|
|
|
cq.Sketch()
|
|
|
|
.trapezoid(hole["width"], hole["height"], 90, mode="a")
|
|
|
|
.vertices()
|
|
|
|
.fillet(hole["fillet"])
|
|
|
|
)
|
|
|
|
.cutBlind(-depth)
|
|
|
|
)
|
2023-03-08 20:24:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
def punch_hole2(*, model, face, w, h, x_offset, y_offset, hole, depth):
|
|
|
|
return (
|
|
|
|
model.faces(face)
|
|
|
|
.workplane(centerOption="CenterOfBoundBox")
|
|
|
|
.center(-w / 2 + x_offset + hole["x"], -h / 2 + y_offset + hole["y"])
|
|
|
|
.placeSketch(hole["shape"])
|
|
|
|
.cutBlind(-depth)
|
2023-03-15 14:17:39 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
def hex_vents(*, size, width, height):
|
|
|
|
vent_positions = []
|
|
|
|
for x in range(1, width // size):
|
|
|
|
for y in range(1, int(height // size / 0.8)):
|
|
|
|
vent_positions.append(
|
|
|
|
(
|
|
|
|
(x + (y % 2) / 2) * size - size * 0.2,
|
|
|
|
y * size * 0.8 + size * 0.2,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
vents = [
|
|
|
|
{
|
|
|
|
"x": 0,
|
|
|
|
"y": 0,
|
|
|
|
"shape": cq.Sketch().push(vent_positions).regularPolygon((size) / 2, 6),
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
return vents
|