76 lines
1.8 KiB
Python
76 lines
1.8 KiB
Python
from utils import extrude_shape, punch_hole
|
|
import cadquery as cq
|
|
|
|
elements = None
|
|
bottom_holes = None
|
|
|
|
|
|
def init(positions, thickness):
|
|
"""Because these need to match in multiple models, we create the
|
|
elemments dynamically"""
|
|
global elements, bottom_holes
|
|
elements = [
|
|
{
|
|
"x": 0,
|
|
"y": 0,
|
|
"shape": cq.Sketch().push(positions).trapezoid(12, 12, 90, mode="a"),
|
|
"height": thickness,
|
|
}
|
|
]
|
|
|
|
bottom_holes = [
|
|
{
|
|
"x": 0,
|
|
"y": 0,
|
|
"shape": cq.Sketch().push(positions).circle(3, mode="a"),
|
|
"depth": thickness - 13, # (screw thread length - threaded insert depth)
|
|
},
|
|
{
|
|
"x": 0,
|
|
"y": 0,
|
|
"shape": cq.Sketch().push(positions).circle(1.8, mode="a"),
|
|
"depth": 100,
|
|
},
|
|
]
|
|
|
|
|
|
def add(
|
|
*,
|
|
model,
|
|
width,
|
|
height,
|
|
thickness,
|
|
offset_x,
|
|
offset_y,
|
|
bottom_face,
|
|
back_face,
|
|
shell_t
|
|
):
|
|
if bottom_face:
|
|
# Mounting pillars
|
|
for element in elements:
|
|
model = extrude_shape(
|
|
model=model,
|
|
face=bottom_face,
|
|
w=width,
|
|
h=height,
|
|
x_offset=offset_x,
|
|
y_offset=shell_t + offset_y,
|
|
element=element,
|
|
height=-(element["height"] + shell_t),
|
|
)
|
|
# Screw holes
|
|
for hole in bottom_holes:
|
|
model = punch_hole(
|
|
model=model,
|
|
face=bottom_face,
|
|
w=width,
|
|
h=height,
|
|
x_offset=offset_x,
|
|
y_offset=shell_t + offset_y,
|
|
hole=hole,
|
|
depth=hole["depth"],
|
|
)
|
|
|
|
return model
|