import importlib as ir from collections import UserList import cadquery as cq import numpy as np class item_list(UserList): def __init__(self, data): self.data = data self.tag = '' def add_tag(self, tag): self.tag = tag return self def translate(self, x, y, z): all_objs = list() for da in self.data: all_objs.append(da.translate((x, y, z))) return item_list(all_objs) def as_dict(self): all_d = dict() for it, objd in enumerate(self.data): key_name = self.tag + '_' + str(it) all_d[key_name] = objd return all_d import util as u ir.reload(u) def add_panel(wplane, w, d, z_drop, r_hole, extrude_amt, t_back): out = u.add_rect(wplane, w, d + z_drop).extrude(extrude_amt) pts_holes = u.slide_pts(w, d / 2 + z_drop, offset_from_back=163 + t_back, spacing=(64, 160, 64, 45)) out = out.cut( wplane.pushPoints(pts_holes).slot2D(10, r_hole * 2).extrude( 10 * abs(extrude_amt) / extrude_amt)) pts = [[72 + t_back, d / 2 - 21 / 2 + z_drop], [72 + t_back, d / 2 + 21 / 2 + z_drop]] for pt in pts: out = out.cut( wplane.polygon(6, 5.3).extrude(100 * abs(extrude_amt) / extrude_amt).translate( (0, pt[0], pt[1]))) # out = out.cut(wplane.pushPoints(pts).circle(r_hole).extrude(10 * abs(extrude_amt)/extrude_amt )) # for pt in pts: # pt_line = u.n_gon(56, 6, xoff=pt[0], yoff=pt[1]) # out = out.cut(wplane.polyline(pt_line).extrude(10*abs(extrude_amt)/extrude_amt)) return out def create_drawer(w, d, h, tab_override=False, slide_flavor='push-open', front_pts='push-open', slide_on_bottom=False, t_small=None, t_large=None, r_hole=None, add_holes=False, add_fingers=False, vert_tabs = None, slide_width=54): box_width = w box_depth = d box_height = h t1 = t_small t2 = t_large l_plane = cq.Plane(origin=(box_width, 0, 0), xDir=(0, 1, 0), normal=(1, 0, 0)) r_plane = cq.Plane(origin=(0, 0, 0), xDir=(0, 1, 0), normal=(1, 0, 0)) f_plane = cq.Plane(origin=(box_width, box_depth, 0), xDir=(-1, 0, 0), normal=(0, 1, 0)) def xy_wp(): return cq.Workplane('XY') def xz_wp(): return cq.Workplane('XZ') def yz_wp(): return cq.Workplane('YZ') def l_wp(): return cq.Workplane(l_plane) def f_wp(): return cq.Workplane(f_plane) bottom = u.add_rect(xy_wp(), box_width, box_depth).extrude(t2).translate( (0, 0, 2)) l_side = u.add_rect(l_wp(), box_depth, box_height).extrude(-t2) r_side = u.add_rect(yz_wp(), box_depth, box_height).extrude(t2) b_side = u.add_rect(xz_wp(), box_width, box_height).extrude(-t2) f_side = u.add_rect(f_wp(), box_width, box_height).extrude(-t2) rect_cut = u.add_rect(xy_wp(), slide_width, 1.2*box_depth, offy=0, offx=box_width/2 - slide_width/2).extrude(t2) if add_holes: pts_holes = u.slide_pts(box_depth, box_height / 2, which=slide_flavor) if slide_flavor=="24inch": idx_s = 0 else: idx_s = 1 r_side = r_side.cut( yz_wp().pushPoints(pts_holes).circle(r_hole).extrude(10)) r_side = r_side.cut(yz_wp().pushPoints(pts_holes[idx_s:]).slot2D( 10, r_hole * 2).extrude(10)) l_side = l_side.cut( l_wp().pushPoints(pts_holes).circle(r_hole).extrude(-10)) l_side = l_side.cut(l_wp().pushPoints(pts_holes[idx_s:]).slot2D( 10, r_hole * 2).extrude(-10)) # if slide_flavor == "24inch": # pts_holes = u.slide_pts(box_depth, box_width / 2, which=slide_flavor) # pts_holes = [[x[1], x[0]] for x in pts_holes] # bottom = bottom.cut( # xy_wp().pushPoints(pts_holes).circle(r_hole).extrude(10)) # bottom = bottom.cut(xy_wp().pushPoints(pts_holes[1:]).slot2D( # 10, r_hole * 2, angle=90).extrude(10)) pts_holes = u.slide_pts(box_depth, box_height / 2, reverse=True, which=slide_flavor) if slide_flavor=="24inch": pts_holes[0], pts_holes[2] = pts_holes[2], pts_holes[0] pts_holes[2], pts_holes[1] = pts_holes[1], pts_holes[2] idx_t = 2 else: idx_t = 1 r_side = r_side.cut( yz_wp().pushPoints(pts_holes).circle(r_hole).extrude(10)) r_side = r_side.cut(yz_wp().pushPoints(pts_holes[idx_t:]).slot2D( 10, r_hole * 2).extrude(10)) l_side = l_side.cut( l_wp().pushPoints(pts_holes).circle(r_hole).extrude(-10)) l_side = l_side.cut(l_wp().pushPoints(pts_holes[idx_t:]).slot2D( 10, r_hole * 2).extrude(-10)) # pts_holes = u.slide_pts(box_depth, # box_width / 2, # reverse=True, # which=slide_flavor) # pts_holes = [[x[1], x[0]] for x in pts_holes] # if slide_flavor == "24inch": # bottom = bottom.cut( # xy_wp().pushPoints(pts_holes).circle(r_hole).extrude(10)) # bottom = bottom.cut(xy_wp().pushPoints(pts_holes[1:]).slot2D( # 10, r_hole * 2, angle=90).extrude(10)) bw = box_width * 0.6 if front_pts == '24inch': f_side = f_side.cut(f_wp().pushPoints( u.ret_front_pts(box_width, box_height * 0.5, spread=0)).circle(r_hole).extrude(-10)) else: f_side = f_side.cut(f_wp().pushPoints( u.ret_front_pts(box_width, box_height * 0.3, spread=bw)).circle(r_hole).extrude(-10)) f_side = f_side.cut(f_wp().pushPoints( u.ret_front_pts(box_width, box_height * (0.7), spread=bw)).circle(r_hole).extrude(-10)) f_side = f_side.cut(f_wp().pushPoints( u.ret_front_pts(box_width, box_height * (0.7), spread=0)).circle(r_hole).extrude(-10)) f_side = f_side.cut(f_wp().pushPoints( u.ret_front_pts(box_width, box_height * (0.3), spread=0)).circle(r_hole).extrude(-10)) if add_fingers: r_side, f_side, _ = u.do_fingers(r_side, f_side, num_tabs = vert_tabs) l_side, f_side, _ = u.do_fingers(l_side, f_side, num_tabs = vert_tabs) l_side, b_side, _ = u.do_fingers(l_side, b_side, num_tabs = vert_tabs) r_side, b_side, _ = u.do_fingers(r_side, b_side, num_tabs = vert_tabs) bottom, l_side, _ = u.do_fingers(bottom, l_side, num_tabs=15) bottom, r_side, _ = u.do_fingers(bottom, r_side, num_tabs=15) bottom, f_side, _ = u.do_fingers(bottom, f_side, num_tabs=15) if tab_override: bottom, b_side, _ = u.do_fingers(bottom, b_side, num_tabs=15, skip_list=[1, 2, 3]) else: bottom, b_side, _ = u.do_fingers(bottom, b_side, num_tabs=15) if slide_on_bottom: b_side = b_side.cut(rect_cut) f_side = f_side.cut(rect_cut) return item_list([bottom, b_side, l_side, f_side, r_side])