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