3d part design with OpenScad #47- Add an O-ring groove to any .stl file.

An easy way to add an O-ring groove to an existing .stl file with OpenScad

2 min read
By Bob
3d part design with OpenScad #47- Add an O-ring groove to any .stl file.

I recycled the code from the Torus module to add an O-ring groove anywhere you want on an existing .stl file. I also made it so you can visualize where the groove will be positioned and so the O-ring groove can be made to fit many different shapes.

Here is the code:

/*[O_ring]*/
Path_to_STL_File ="/home/none3/Desktop/YourFileName.stl";
Show_O_ring = true;
Show_Cut_Plane = true;

O_ring_Diameter = 10; //[.1:0.01:400]
O_ring_Circle_Radius = 1; //[.1:0.01:400]
O_ring_Fragments = 100; //[3:1:200]
O_ring_outside_shape =100; //[3:1:200]
Groove_rotate =45; //[0:1:360]
Rotate_O_ring_X = 0; //[0:0.01:360]
Rotate_O_ring_Y = 0; //[0:0.01:360]
Rotate_O_ring_Z = 0; //[0:0.01:360]
Move_O_ring_X = 0; //[-400:0.01:400] 
Move_O_ring_Y = 0; //[-400:0.01:400]
Move_O_ring_Z = 0; //[-400:0.01:400]
Scale_O_ring_X = 1; //[1:0.01:100]
Scale_O_ring_Y = 1; //[1:0.01:100]
Scale_O_ring_Z = 1; //[1:0.01:100] 


//***O_ring***//
module O_ring(){
InnerRadius = O_ring_Circle_Radius/2; 
OuterRadius = O_ring_Diameter/2-O_ring_Circle_Radius/2;      
rotate(a = [Rotate_O_ring_X,0,0])
rotate(a = [0,Rotate_O_ring_Y,0])
rotate(a = [0,0,Rotate_O_ring_Z])
translate([Move_O_ring_X,0,0]) 
translate([0,Move_O_ring_Y,0])
translate([0,0,Move_O_ring_Z]) 
scale([Scale_O_ring_X,1,1])
scale([1,Scale_O_ring_Y,1])
scale([1,1,Scale_O_ring_Z])
if (Show_O_ring)
{    
rotate_extrude(convexity=10,$fn=O_ring_Fragments) 
translate([O_ring_Diameter, 0, 0])
rotate([0,0,Groove_rotate])
circle(r=O_ring_Circle_Radius,$fn=O_ring_outside_shape);
}}
//
difference(){
import(Path_to_STL_File,convexity=11);
O_ring();
}
if (Show_Cut_Plane){
%O_ring();
}
//

The grove can be made square, round or have multiple sides and be rotated to accommodate different angles:

Many interesting new shapes can also be made out of an existing .stl file:

keep in mind an error will occur if your "circle radius" is larger than the diameter of the torus:

There are several improvements I can think of >and I will probably make, but for a quick way to add an O-ring groove to an existing file this works really well.