mill_endstop_holder.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import cadquery as cq
  2. from cadquery.occ_impl.exporters import *
  3. from ocp_vscode import show
  4. pipe_diam = 25.1
  5. clip_thickness = 5
  6. clip_gap = 1.5
  7. clip_height = 12
  8. clip_holes_diam = 4.1
  9. total_thickness = 15
  10. holder_height = 25
  11. # Create the ring by defining two concentric circles and extruding them
  12. clip = (
  13. cq.Workplane("XY") # Start in the XY plane
  14. .circle(pipe_diam/2)
  15. .circle(pipe_diam/2+clip_thickness)
  16. .extrude(total_thickness) # Extrude to the specified height
  17. )
  18. clip_with_holes = (
  19. clip
  20. .faces(">Z")
  21. .workplane()
  22. .rect(pipe_diam+(clip_thickness+clip_height)*2, clip_gap+clip_thickness*2)
  23. .extrude(-total_thickness)
  24. .faces(">Y")
  25. .workplane(origin=(pipe_diam/2+clip_thickness+clip_height/2, 0, total_thickness/2))
  26. .circle(clip_holes_diam/2)
  27. .cutThruAll()
  28. .faces(">Y")
  29. .workplane(origin=(-(pipe_diam/2+clip_thickness+clip_height/2), 0, total_thickness/2))
  30. .circle(clip_holes_diam/2)
  31. .cutThruAll()
  32. )
  33. clip_with_ends = clip.union(
  34. clip_with_holes
  35. )
  36. clip_with_gap = (
  37. clip_with_ends
  38. .faces(">Z")
  39. .workplane(centerOption="CenterOfMass")
  40. .rect(pipe_diam+(clip_thickness+clip_height)*2, clip_gap)
  41. .cutThruAll()
  42. .circle(pipe_diam/2)
  43. .cutThruAll()
  44. )
  45. result = clip_with_gap.union(
  46. clip_with_gap
  47. .faces(">X")
  48. .workplane(origin=(0, (clip_thickness + clip_gap)/2, total_thickness/2))
  49. .rect(clip_thickness, total_thickness)
  50. .extrude(holder_height)
  51. ).fillet(1)
  52. show(result)
  53. # export the box as a STEP file
  54. with open("/home/sgruen/Dokumente/cadquery/mill-endstop.step", "w") as fp:
  55. cq.exporters.exportShape(result, ExportTypes.STEP, fp)