zellhalter_v2.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. strip_width = 10.2
  14. # board_connector_length =
  15. print_height = 10
  16. wall_thick = 1.5
  17. eps = 0.1
  18. ############
  19. cell_locs = [(x * space_single, y * space_rows) for x in range(0, cells_per_row) for y in range(0, rows)]
  20. strip_locs = [(-cell_diam/4, y * space_rows) for y in range(0, rows)]
  21. 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)]
  22. cell_base = (
  23. cq.Workplane()
  24. .pushPoints(cell_locs)
  25. .eachpoint(
  26. lambda loc: (
  27. cq.Workplane()
  28. .circle(cell_diam/2 + eps + wall_thick)
  29. .extrude(print_height)
  30. .val()
  31. .located(loc)
  32. )
  33. )
  34. )
  35. cell_cutout = (
  36. cq.Workplane()
  37. .pushPoints(cell_locs)
  38. .eachpoint(
  39. lambda loc: (
  40. cq.Workplane()
  41. .circle(cell_diam/2 + eps )
  42. .extrude(print_height-wall_thick)
  43. .val()
  44. .located(loc)
  45. )
  46. )
  47. )
  48. strips_cut = (
  49. cq.Workplane()
  50. .pushPoints(strip_locs)
  51. .eachpoint(
  52. lambda loc: (
  53. cq.Workplane()
  54. .rect(space_all + cell_diam/2, strip_width, centered=(False, True))
  55. .extrude(print_height)
  56. .val()
  57. .located(loc)
  58. )
  59. )
  60. )
  61. strips_wall = (
  62. cq.Workplane()
  63. .pushPoints(strip_locs)
  64. .eachpoint(
  65. lambda loc: (
  66. cq.Workplane()
  67. .rect(space_all, strip_width, centered=(False, True))
  68. .center(-wall_thick, 0)
  69. .rect(space_all+ 2*wall_thick, strip_width + 2*wall_thick, centered=(False, True))
  70. .extrude(print_height)
  71. .val()
  72. .located(loc)
  73. )
  74. )
  75. )
  76. base_cutout = (
  77. cell_base.union(strips_wall)
  78. .cut(cell_cutout)
  79. .cut(strips_cut)
  80. ).faces("<Z").chamfer(wall_thick/4)
  81. connectors = (
  82. cq.Workplane()
  83. .pushPoints(connector_locs)
  84. .eachpoint(
  85. lambda loc: (
  86. cq.Workplane().workplane(offset=wall_thick)
  87. .rect(wall_thick, space_rows - cell_diam - wall_thick, centered=(False, True))
  88. .extrude(print_height-wall_thick)
  89. .val()
  90. .located(loc)
  91. )
  92. )
  93. )
  94. base_connected = base_cutout.union(connectors)
  95. show_object(base_connected)
  96. with open(r"/home/sgruen/Dokumente/bodenplatte/zellhalter_v2.step", "w") as fp:
  97. cq.exporters.exportShape(cell_base, ExportTypes.STEP, fp)