Advertisement
Guest User

https://www.reddit.com/r/3Drequests/comments/1kiwq2f/request_to_make_a_model/

a guest
May 9th, 2025
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | Source Code | 0 0
  1. // Reddit request:
  2. // https://www.reddit.com/r/3Drequests/comments/1kiwq2f/request_to_make_a_model/
  3. //
  4. // Open the "Customizer" window in OpenSCAD,
  5. // then use the sliders.
  6. //
  7. // Version 1, CC0
  8.  
  9. // Accuracy, higher is more accurate and slower.
  10. $fn = 100; // [10:200]
  11.  
  12. // The diameter of the tubes.
  13. tube_diameter = 8; // [3:15]
  14.  
  15. // The number of tubes.
  16. number_tubes = 4; // [1:10]
  17.  
  18. // The tubes overlap each other a little.
  19. tube_overlap = 2; // [0:5]
  20.  
  21. // The offset start of the first tube.
  22. tube_start = 5; // [0:0.1:20]
  23.  
  24. // The gap width for the switch.
  25. gap_width = 18; // [3:30]
  26.  
  27. // The gap height for the switch.
  28. gap_height = 50; // [10:100]
  29.  
  30. // The radius of the round corner of the gap.
  31. gap_corner = 1; // [0:5]
  32.  
  33. // How much of the bottom is removed.
  34. bottom_start = 1; // [0:10]
  35.  
  36. // Add the gap for the switch.
  37. // Remove some from the bottom.
  38. difference()
  39. {
  40. CoverNoGap();
  41.  
  42. linear_extrude(100,center=true)
  43. SquareGap2D();
  44.  
  45. // Some of the bottom is removed.
  46. // The size of the cube that is used
  47. // is a don't care, it should be
  48. // large enough.
  49. translate([0,0,-200-tube_diameter/2+bottom_start])
  50. cube(400,center=true);
  51. }
  52.  
  53. module CoverNoGap()
  54. {
  55. // The two circular tubes.
  56. for(m=[0,1])
  57. mirror([0,m,0])
  58. translate([0,gap_height/2,0])
  59. CircularTubes();
  60.  
  61. // The parallel tubes.
  62. for(m=[0,1])
  63. mirror([m,0,0])
  64. ParalelTubes();
  65.  
  66. Base();
  67. }
  68.  
  69. module Base()
  70. {
  71. // Put a base under it.
  72. radius = tube_start
  73. + number_tubes*tube_diameter
  74. - (number_tubes-1)*tube_overlap
  75. - tube_diameter/2;
  76. translate([0,0,-tube_diameter/2])
  77. linear_extrude(tube_diameter/2)
  78. hull()
  79. for(m=[0,1])
  80. mirror([0,m,0])
  81. translate([0,gap_height/2,0])
  82. circle(radius);
  83. }
  84.  
  85. module ParalelTubes()
  86. {
  87. delta = tube_diameter - tube_overlap;
  88.  
  89. for(i=[0:number_tubes-1])
  90. translate([tube_start + i*delta,0,0])
  91. rotate([90,0,0])
  92. cylinder(h=gap_height,d=tube_diameter,center=true);
  93. }
  94.  
  95. module CircularTubes()
  96. {
  97. delta = tube_diameter - tube_overlap;
  98. for(i=[0:number_tubes-1])
  99. HalfTorus(tube_start + i*delta);
  100. }
  101.  
  102. // Create half a torus.
  103. // In the direction of the y-axis.
  104. // The center of the tube starts at [x,0].
  105. module HalfTorus(x)
  106. {
  107. rotate_extrude(180)
  108. translate([x,0])
  109. circle(d=tube_diameter);
  110. }
  111.  
  112. module SquareGap2D()
  113. {
  114. // give it round corners with offset().
  115. offset(gap_corner)
  116. offset(-gap_corner)
  117. square([gap_width,gap_height],center=true);
  118. }
Tags: OpenSCAD
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement