zellhalter_v2.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. import cadquery as cq
  2. from cadquery.occ_impl.exporters import ExportTypes
  3. from ocp_vscode import show, show_object
  4. ###### Parameter #####
  5. cells_per_row = 8
  6. rows = 2
  7. cell_diam = 18.44
  8. cell_length = 65
  9. dist_to_ground = 66.9
  10. space_all = 140
  11. space_single = space_all / (cells_per_row - 1)
  12. space_rows = 33.7
  13. dist_segments = 57.5
  14. strip_width = 10.2
  15. print_height = 15
  16. wall_thick = 1.7
  17. eps = 0.1
  18. hole_diam = 2.4
  19. hole_depth = 10
  20. board_connector_length = dist_to_ground + wall_thick + eps
  21. lip_width = 1.5
  22. lip_thick = 1.5
  23. ############
  24. cell_locs = [(x * space_single, y * space_rows) for x in range(0, cells_per_row) for y in range(0, rows)]
  25. strip_locs = [(-cell_diam/4, y * space_rows) for y in range(0, rows)]
  26. 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)]
  27. cell_edge = cell_diam/2 - 1.5
  28. board_con_locs = [
  29. (-.5 * space_single, -cell_edge),
  30. (-.5 * space_single, space_rows + cell_edge),
  31. (1.5 * space_single, space_rows - cell_edge),
  32. (5.5 * space_single, cell_edge),
  33. (5.5 * space_single, space_rows - cell_edge)
  34. ]
  35. cell_base = (
  36. cq.Workplane()
  37. .pushPoints(cell_locs)
  38. .eachpoint(
  39. lambda loc: (
  40. cq.Workplane()
  41. .circle(cell_diam/2 + eps + wall_thick)
  42. .extrude(print_height)
  43. .val()
  44. .located(loc)
  45. )
  46. )
  47. )
  48. cell_cutout = (
  49. cq.Workplane()
  50. .pushPoints(cell_locs)
  51. .eachpoint(
  52. lambda loc: (
  53. cq.Workplane()
  54. .circle(cell_diam/2 + eps)
  55. .extrude(print_height-wall_thick)
  56. .val()
  57. .located(loc)
  58. )
  59. )
  60. )
  61. strips_cut = (
  62. cq.Workplane()
  63. .pushPoints(strip_locs)
  64. .eachpoint(
  65. lambda loc: (
  66. cq.Workplane().workplane(offset=print_height-wall_thick)
  67. .rect(space_all + cell_diam/2, strip_width, centered=(False, True))
  68. .extrude(wall_thick)
  69. .val()
  70. .located(loc)
  71. )
  72. )
  73. )
  74. strips_wall = (
  75. cq.Workplane()
  76. .pushPoints(strip_locs)
  77. .eachpoint(
  78. lambda loc: (
  79. cq.Workplane()
  80. .rect(space_all+ 2*wall_thick, strip_width + 2*wall_thick, centered=(False, True))
  81. .extrude(print_height)
  82. .val()
  83. .located(loc)
  84. )
  85. )
  86. )
  87. base_cutout = (
  88. cell_base.union(strips_wall)
  89. .cut(cell_cutout)
  90. .cut(strips_cut)
  91. )#.faces("<Z").chamfer(wall_thick/4)
  92. connectors = (
  93. cq.Workplane()
  94. .pushPoints(connector_locs)
  95. .eachpoint(
  96. lambda loc: (
  97. cq.Workplane().workplane(offset=wall_thick)
  98. .rect(wall_thick, space_rows - cell_diam - wall_thick, centered=(False, True))
  99. .extrude(print_height-wall_thick)
  100. .val()
  101. .located(loc)
  102. )
  103. )
  104. )
  105. base_connected = base_cutout.union(connectors)
  106. connector_width = hole_diam + wall_thick*2
  107. board_con = (
  108. cq.Workplane()
  109. .rect(connector_width, connector_width)
  110. .extrude(board_connector_length)
  111. .faces("<Z")
  112. .workplane()
  113. .rect(connector_width+lip_width, connector_width+lip_width)
  114. .extrude(lip_width)
  115. .edges("|Z")
  116. .chamfer(wall_thick)
  117. .faces(">Z")
  118. .workplane()
  119. .circle(hole_diam/2)
  120. .cutBlind(-hole_depth)
  121. )
  122. board_con_outside = (
  123. cq.Workplane()
  124. .rect(connector_width + eps, connector_width + eps)
  125. .extrude(print_height)
  126. .edges("|Z")
  127. .chamfer(wall_thick)
  128. )
  129. board_con_hull = (
  130. cq.Workplane()
  131. .rect(connector_width + 2 * (wall_thick + eps), connector_width + 2 * (wall_thick + eps))
  132. .extrude(print_height)
  133. .edges("|Z")
  134. .chamfer(wall_thick)
  135. )
  136. con_placed = []
  137. for loc in board_con_locs:
  138. con = board_con.translate(loc)
  139. con_outside = board_con_outside.translate(loc)
  140. con_placed.append(con)
  141. hull = board_con_hull.translate(loc).cut(cell_base).cut(strips_cut)
  142. base_connected = base_connected.union(hull).cut(con_outside)
  143. boundary_box = (
  144. base_connected.workplane(centerOption="CenterOfBoundBox")
  145. .box(1000, dist_segments, 1000,combine=False)
  146. )
  147. base_connected = base_connected.intersect(boundary_box)
  148. show_object(base_connected)
  149. show_object(con_placed)
  150. with open(r"/home/sgruen/Dokumente/bodenplatte/zellhalter_v2_base.step", "w") as fp:
  151. cq.exporters.exportShape(base_connected, ExportTypes.STEP, fp)
  152. with open(r"/home/sgruen/Dokumente/bodenplatte/zellhalter_v2_connector.step", "w") as fp:
  153. cq.exporters.exportShape(board_con, ExportTypes.STEP, fp)