vise_segment.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import cadquery as cq
  2. from cadquery.occ_impl.exporters import *
  3. from cadquery.occ_impl.shapes import intersect
  4. from ocp_vscode import show
  5. import math
  6. result_depth = 65
  7. base_depth = 500
  8. thick = 4
  9. height_rips = 8.7
  10. width_rips = 5
  11. # dist_rips = 17,2
  12. total_dist_rips = 170
  13. angle_deg = 1
  14. num_rips = 11
  15. angle = -30
  16. width_base = total_dist_rips + width_rips
  17. spacing = total_dist_rips / (num_rips - 1) if num_rips > 1 else 0
  18. hole_diam = 6
  19. base = (
  20. cq.Workplane("XY")
  21. .rect(width_base, base_depth)
  22. .extrude(thick)
  23. )
  24. boxes_locations = []
  25. limit_lo = math.floor(num_rips/2)
  26. limit_hi = math.ceil(num_rips/2)
  27. for i in range(-limit_lo, limit_hi):
  28. boxes_locations.append((i * spacing, 0))
  29. boxes = (
  30. base.faces(">Z")
  31. .workplane()
  32. .pushPoints(boxes_locations)
  33. .eachpoint(
  34. lambda loc: (
  35. cq.Workplane()
  36. .rect(width_rips, base_depth)
  37. .extrude(height_rips)
  38. .val()
  39. .located(loc)
  40. )
  41. )
  42. )
  43. result = base.union(boxes).rotateAboutCenter((0,0,1), angle)
  44. cutout = (
  45. result.workplane(centerOption="CenterOfBoundBox")
  46. .box(base_depth, result_depth, thick+height_rips, combine=False)
  47. )
  48. cutted_res = cutout * result
  49. show(cutted_res)
  50. # export the box as a STEP file
  51. with open("/home/sgruen/Dokumente/cadquery/vise_segment_base.step", "w") as fp:
  52. cq.exporters.exportShape(cutted_res, ExportTypes.STEP, fp)