| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202 |
- import cadquery as cq
- from cadquery.occ_impl.exporters import ExportTypes
- from ocp_vscode import show, show_object
- ###### Parameter #####
- cells_per_row = 8
- rows = 2
- cell_diam = 18.44
- cell_length = 65
- dist_to_ground = 66.9
- space_all = 140
- space_single = space_all / (cells_per_row - 1)
- space_rows = 33.7
- dist_segments = 57.5
- strip_width = 10.4
- print_height = 15
- wall_thick = 1.7
- eps = 0.15
- hole_diam = 2.4
- hole_depth = 10
- board_connector_length = dist_to_ground + wall_thick
- lip_width = 1.5
- lip_thick = 1.5
- injection_mould = False
- ############
- cell_locs = [(x * space_single, y * space_rows) for x in range(0, cells_per_row) for y in range(0, rows)]
- strip_locs = [(-cell_diam/4, y * space_rows) for y in range(0, rows)]
- connector_locs = [(x * space_single * 2, (y + 0.5) * space_rows) for x in range(0, int(cells_per_row/2)) for y in range(0, rows-1)]
- cell_edge = cell_diam/2 - 1.5
- board_con_locs_with_rot = [
- ((-.5 * space_single, -cell_edge), 0),
- ((-.5 * space_single, space_rows + cell_edge), 180),
- ((1.5 * space_single, space_rows - cell_edge), 0),
- ((5.5 * space_single, cell_edge), 180),
- ((5.5 * space_single, space_rows - cell_edge), 0),
- ]
- # Zellkreise
- cell_base = (
- cq.Workplane()
- .pushPoints(cell_locs)
- .eachpoint(
- lambda loc: (
- cq.Workplane()
- .circle(cell_diam/2 + eps + wall_thick)
- .extrude(print_height)
- .val()
- .located(loc)
- )
- )
- )
- # Ausschnitt für die Zellen
- cell_cutout = (
- cq.Workplane()
- .pushPoints(cell_locs)
- .eachpoint(
- lambda loc: (
- cq.Workplane()
- .circle(cell_diam/2 + eps)
- .extrude(print_height-wall_thick)
- .val()
- .located(loc)
- )
- )
- )
- # Ausschnitt für die Lötfahne
- strips_cut = (
- cq.Workplane()
- .pushPoints(strip_locs)
- .eachpoint(
- lambda loc: (
- cq.Workplane().workplane(offset=print_height-2*wall_thick)
- .rect(space_all + cell_diam/2+wall_thick, strip_width, centered=(False, True))
- .extrude(wall_thick*2)
- # Dreieckiger Ausschnitt für besseres bridging
- .faces("<Z")
- .workplane()
- .rect(space_all + cell_diam/2+wall_thick, strip_width, centered=(False, True))
- .workplane(offset=wall_thick*2)
- .rect(space_all + cell_diam/2+wall_thick, eps, centered=(False, True))
- .loft()
- .val()
- .located(loc)
- )
- )
- )
- strips_wall = (
- cq.Workplane()
- .pushPoints(strip_locs)
- .eachpoint(
- lambda loc: (
- cq.Workplane()
- .rect(space_all+ 2*wall_thick, strip_width + 2*wall_thick, centered=(False, True))
- .extrude(print_height)
- .val()
- .located(loc)
- )
- )
- )
- base_cutout = (
- cell_base.union(strips_wall)
- .cut(cell_cutout)
- .cut(strips_cut)
- )#.faces("<Z").chamfer(wall_thick/4)
- connectors = (
- cq.Workplane()
- .pushPoints(connector_locs)
- .eachpoint(
- lambda loc: (
- cq.Workplane().workplane(offset=wall_thick)
- .rect(wall_thick, space_rows - cell_diam - wall_thick, centered=(False, True))
- .extrude(print_height-wall_thick)
- .val()
- .located(loc)
- )
- )
- )
- base_connected = base_cutout.union(connectors)
- connector_width = hole_diam + wall_thick*1.5
- board_con = (
- cq.Workplane()
- .rect(connector_width, connector_width)
- .extrude(board_connector_length)
- .faces("+Y")
- .edges("|Z")
- .chamfer(wall_thick)
- .faces(">Z")
- .workplane()
- .circle(hole_diam/2)
- .cutBlind(-hole_depth)
- )
- if not injection_mould:
- board_con = (
- board_con
- .faces("<Z")
- .workplane()
- .rect(connector_width+lip_width, connector_width)
- .extrude(lip_width)
- )
- board_con_outside = (
- cq.Workplane()
- .rect(connector_width + 2 * eps, connector_width + 2 * eps)
- .extrude(print_height)
- )
- board_con_hull = (
- cq.Workplane()
- .rect(connector_width + 2 * (wall_thick + eps), connector_width + 2 * (wall_thick + eps))
- .extrude(print_height)
- .edges("|Z")
- .chamfer(wall_thick)
- )
- base_connected = base_connected.rotateAboutCenter((1,0,0), 180)
- con_placed = []
- for location, angle in board_con_locs_with_rot:
- # Connector nur für Visualisierung
- con = board_con.translate(location)
- con = con.rotateAboutCenter((0,0,1), angle)
- # Ausschnitt für den Connector
- chamfer_face = "-Y" if angle >= 180 else "+Y"
- con_outside = board_con_outside.faces(chamfer_face).edges("|Z").chamfer(wall_thick)
- con_outside = con_outside.translate(location)
- con_placed.append(con)
- # Verdickte Hülle für den Connector
- hull = board_con_hull.translate(location).cut(cell_base).cut(strips_cut)
- base_connected = base_connected.union(hull)
- if injection_mould:
- base_connected = base_connected.union(con)
- else:
- base_connected = base_connected.cut(con_outside)
- # Begrenzungsbox für den gesamten Zellhalter (sonst schneidet man den nächsten Halter)
- boundary_box = (
- base_connected.workplane(centerOption="CenterOfBoundBox")
- .box(1000, dist_segments, 1000,combine=False)
- )
- base_connected = base_connected.intersect(boundary_box)
- show_object(base_connected)
- show_object(con_placed)
- with open(r"zellhalter_v2_base.step", "w") as fp:
- cq.exporters.exportShape(base_connected, ExportTypes.STEP, fp)
- if not injection_mould:
- with open(r"zellhalter_v2_connector.step", "w") as fp:
- cq.exporters.exportShape(board_con, ExportTypes.STEP, fp)
|