from cadquery import exporters from cq_warehouse.extensions import Workplane from cq_warehouse.fastener import * from cq_warehouse.thread import * from cqmore.curve import archimedeanSpiral, circle from cqmore.polygon import regularPolygon, star from cqmore.polyhedron import polarZonohedra, Polyhedron, superellipsoid from svg_path import addSvgPath from svgpathtools import svg2paths import cadquery as cq import cqmore from math import ceil, floor Workplane = cqmore.extend(Workplane) Workplane.addSvgPath = addSvgPath headphone_path, headphone_attribute = svg2paths( "/home/deck/cad_files/svgs/headphones.svg" ) side_width = 5 bottom_width = 5 middle_width = 2 panel_width = 1.5 amp_bottom_height = 19 + bottom_width + middle_width # how tall the pcb is battery_width = 26 battery_height = 15 amp_width = 62 amp_length = 56 amp_height = battery_height + amp_bottom_height top_width = 1.3 panel_component_diameter = 7.8 panel_distance = 10.5 + ( panel_component_diameter / 2 ) # distance between each panel component panel_dist_from_side = 2 panel_dist_from_bottom = 0 # how far the panel components are from the bottom result = Workplane().box(amp_length, amp_width, middle_width) result = ( result.workplane(offset=0) .center(0, -(amp_width / 2)) .line(0, amp_width, forConstruction=True) .vertices() .box(amp_length, side_width, amp_height) ) # Back slot for cable result = ( result.workplane(offset=amp_height / 2) .center(0, amp_width / 2) .box(amp_length, amp_width + bottom_width, bottom_width) .workplane(offset=-10) .move(-(amp_width / 2), 0) .box(20, 10, 10, combine="cut") ) # Front panel result = ( result.workplane(offset=-6.4) .center((amp_width / 2) - (panel_width / 2) - 3, 0) .box(panel_width, amp_width + 5, amp_height + 2.5) ) in_text = ( Workplane("YZ") .workplane(offset=(amp_width / 2) - 3.5) .center(-15, -2) .text("IN", 7, 2) .rotateAboutCenter((1, 0, 0), 180) ) out_text = ( Workplane("YZ") .workplane(offset=(amp_width / 2) - 3.5) .center(15, -2) .text("OUT", 7, 2) .rotateAboutCenter((1, 0, 0), 180) ) icon = ( Workplane("YZ") .workplane(offset=274.5) .center(-50, -175) .addSvgPath(headphone_path[0]) .extrude(5) .val() .scale(0.10) ) result = result.cut(in_text) result = result.cut(out_text) result = result.cut(icon) panel_holes = ( Workplane("ZY") .workplane(offset=-(amp_length / 2)) .center(panel_component_diameter + panel_dist_from_bottom, 0) .line(0, panel_distance, forConstruction=True) .vertices() .cylinder(side_width, panel_component_diameter / 2) ) panel_holes_2 = ( Workplane("ZY") .workplane(offset=-(amp_length / 2)) .center(panel_component_diameter + panel_dist_from_bottom, 0) .line(0, -(panel_distance), forConstruction=True) .vertices() .cylinder(side_width, panel_component_diameter / 2) ) result = result.cut(panel_holes) result = result.cut(panel_holes_2) # Back panel back = ( result.workplane(offset=-6.3) .center(-(amp_width) + 2, 0) .box(panel_width * 2.5, amp_width + side_width, amp_height + 4) ) back_screws = ( Workplane("ZY") .workplane(offset=(amp_length / 2)) .center(2, 0.0) .rect(37, amp_width, forConstruction=True) .vertices() .cylinder(20, 0.8) ) back = back.cut(back_screws) back = back.center(31.5, 0).box(amp_width, amp_width + 9, amp_width, combine="cut") # Slide in slot for top result = ( result.workplane(offset=-(amp_height / 2) - side_width - 1) .center(-70, -(amp_width / 2)) .line(0, amp_width, forConstruction=True) .vertices() .box(amp_length * 2, 3.5, 1.0, combine="cut") .workplane(offset=-(amp_height / 2) - side_width - 2) .line(0, amp_width, forConstruction=True) .vertices() .box(amp_length * 2, 1.5, 1.5, combine="cut") ) top = ( Workplane() .box(amp_length, amp_width + side_width - 1, top_width) .center(-7.3, -(amp_width / 2)) .workplane(offset=-1.0) .line(0, amp_width, forConstruction=True) .vertices() .box(amp_length - side_width - 10, 1.4, 1.6) .workplane(offset=-2.0) .line(0, amp_width, forConstruction=True) .vertices() .box(amp_length - side_width - 10, 2.0, 0.5) .workplane(offset=-1.5) .center(5, amp_width - side_width * 3) .box(amp_width / 1.5, amp_height / 2, 3.2) .center(0, -((amp_height / 2) + side_width * 2)) .box(amp_width / 1.5, amp_height / 2, 3.2) ) result = result.cut(back_screws) result = ( result.workplane(offset=-(amp_height / 2) + 3) .center(amp_length - 10.5, amp_width / 2) .box(amp_length - 9, 2, (amp_height / 2)) ) cq.exporters.export(result, "/home/deck/model_files/amp_case.step") cq.exporters.export(back, "/home/deck/model_files/amp_case_back.step") cq.exporters.export(top, "/home/deck/model_files/amp_case_top.step") try: # show_object(back) # show_object(front_text) # show_object(result) show_object(top) except NameError: pass