tconnector 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. import cadquery as cq
  2. from cq_warehouse.thread import (
  3. IsoThread
  4. )
  5. from ocp_vscode import show, show_object
  6. from cadquery.occ_impl.exporters import ExportTypes
  7. MM = 1
  8. IN = 25.4 * MM
  9. distance = 10 * MM
  10. seal_diam = 8.2 * MM
  11. seal_depth = 5.4 * MM
  12. seal_torus_diam = 1.5 * MM
  13. cartridge_small_diam = 7.7 * MM
  14. cartridge_small_depth = 7 * MM
  15. cartridge_large_diam = 8.9 * MM
  16. cartridge_large_depth = 3.7 * MM
  17. eps = 0.1 * MM
  18. iso_external_thread = IsoThread(
  19. major_diameter=7 * MM,
  20. pitch=1 * MM,
  21. length=8 * MM,
  22. external=True,
  23. end_finishes=("chamfer", "chamfer"),
  24. )
  25. iso_external_core = (
  26. cq.Workplane("XY")
  27. .circle(iso_external_thread.min_radius)
  28. .extrude(iso_external_thread.length)
  29. )
  30. iso_external = iso_external_thread.cq_object.fuse(iso_external_core.val())
  31. housing_diameter = cartridge_large_diam * 1.5
  32. housing = (
  33. cq.Workplane("XY")
  34. .rect(housing_diameter, housing_diameter)
  35. .workplane(offset=iso_external_thread.length + distance)
  36. .center(0, housing_diameter/2)
  37. .rect(housing_diameter, housing_diameter * 2)
  38. .workplane(offset=iso_external_thread.length)
  39. .rect(housing_diameter, housing_diameter * 2)
  40. .loft()
  41. )
  42. # Side A
  43. housing = housing.cut(iso_external)
  44. # Side B
  45. housing = housing.cut(iso_external.translate((0, 0, iso_external_thread.length + distance)))
  46. # Cartidge hole
  47. housing = (
  48. housing.faces(">Z")
  49. .workplane(centerOption="CenterOfBoundBox")
  50. .center(0, housing_diameter/2)
  51. .circle(cartridge_large_diam / 2)
  52. .cutBlind(-cartridge_large_depth)
  53. )
  54. housing = (
  55. housing.faces(">Z")
  56. .workplane(centerOption="CenterOfBoundBox")
  57. .center(0, housing_diameter/2)
  58. .circle(cartridge_small_diam / 2)
  59. .cutBlind(-cartridge_small_depth)
  60. )
  61. # seal as torus
  62. seal = (
  63. cq.Workplane('XZ', origin = (seal_diam/2, 0, 0))
  64. .circle(seal_torus_diam/2)
  65. .revolve(360, (-seal_diam/2, 0, 0), (-seal_diam/2, 1, 0))
  66. )
  67. seal_position = iso_external_thread.length*2 + distance - seal_depth
  68. seal_moved = seal.translate((0, housing_diameter, seal_position))
  69. housing = housing.cut(seal_moved)
  70. # straight channel
  71. housing = (
  72. housing.faces("<Z")
  73. .circle(iso_external_thread.min_radius)
  74. .cutThruAll()
  75. )
  76. sweep = (
  77. housing.faces(">Z")
  78. .workplane(centerOption="CenterOfBoundBox", offset=-cartridge_small_depth)
  79. .center(0, housing_diameter/2)
  80. .circle(cartridge_small_diam / 2)
  81. .workplane(offset=cartridge_small_diam/2-(iso_external_thread.length + distance/2))
  82. .center(0, -housing_diameter)
  83. .transformed(rotate=(-90, 0, 0))
  84. .circle(seal_diam / 2)
  85. .loft(combine=False)
  86. )
  87. housing = housing.cut(sweep)
  88. # show_object(iso_external_thread.cq_object, name="iso_external_thread")
  89. # show_object(iso_external_core, name="iso_external_core")
  90. # show_object(iso_external, name="iso_external")
  91. show_object(housing, name="housing")
  92. with open(r"t_connector.step", "w") as fp:
  93. cq.exporters.exportShape(housing, ExportTypes.STEP, fp)