#!/usr/bin/env python3 # type: ignore #************************************************************************** # Copyright (C) 2025, Paul Lutus * # * # This program is free software; you can redistribute it and/or modify * # it under the terms of the GNU General Public License as published by * # the Free Software Foundation; either version 2 of the License, or * # (at your option) any later version. * # * # This program is distributed in the hope that it will be useful, * # but WITHOUT ANY WARRANTY; without even the implied warranty of * # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * # GNU General Public License for more details. * # * # You should have received a copy of the GNU General Public License * # along with this program; if not, write to the * # Free Software Foundation, Inc., * # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * #************************************************************************** import cadquery as cq import math, sys # classic interpolation algorithm def ntrp(x, xa, xb, ya, yb): return (x - xa) * (yb - ya) / (xb - xa) + ya def save_part(data, name): path = f"{name}.stl" cq.exporters.export(data, path) print(f'Saved "{path}"') def build_container(length, width, height, wall_thickness, corner_radius): box = ( cq.Workplane("XY") .rect(length + wall_thickness, width + wall_thickness) .extrude(height) .edges("|Z") .fillet(corner_radius + wall_thickness / 2) ) box_interior = ( cq.Workplane("XY") .rect(length, width) .extrude(height) .edges("|Z") .fillet(corner_radius) .translate((0, 0, wall_thickness)) ) return box - box_interior def main(): # box data, all dimensions mm name = "box" wall_thickness = 3 # these are interior dimensions for the main container length = 204 width = 114 height = 140 # curvature at corners corner_radius = 20 # this determines the tightness of fit between body and cover body_cover_gap = 0.05 cover_edge_height = 20 container = build_container(length, width, height + wall_thickness, wall_thickness, corner_radius) save_part(container, f"{name}_container") cover_length = length + wall_thickness + body_cover_gap cover_width = width + wall_thickness + body_cover_gap cover = build_container( cover_length, cover_width, cover_edge_height, wall_thickness, corner_radius + wall_thickness / 2, ) save_part(cover, f"{name}_cover") if __name__ == "__main__": main()