3D part design with OpenSCAD #133: Customizable vented screw cap.

3 min read
By Bob
3D part design with OpenSCAD #133: Customizable vented screw cap.

I was experimenting with the thread module I made in post #71:

3d part design with OpenScad #71: Using hull and spheres to make a slinky
An example of how to use a sphere and hull to make a smoother spiral.

to see if I could make threads for a screw cap customizer that I could use to make caps for gas cans, etc. I took out a bunch of the thread code I didn't need then added the capability to have adjustable cap size, center hole size, exterior ridges and vent ridges.

Here is the code:

//
/*[Cap]*/
Cap_diameter=90;//[1:.01:400]
Cap_height=50;//[1:.01:400]
wall_thickness=4.20;//[2.5:.01:6]
Ridge_width=12;//[1:.01:80]
Ridge_depth=2;//[1:.01:5]
Ridge_number=6;//[3:1:12]

/*[Cap Center Hole]*/
Hole_size=26;//[0:.01:200]
Thickness=8;//[3:.01:10]

/*[Threads]*/
Thread_pitch = 6;//[0:.001:16]
Thread_shape = 5;//[3:1:10]
Thread_thickness = 2.8;//[.1:.001:4]
Tn=100*Thread_pitch;
Pitch_angle=360*Thread_pitch;

/*[Thread vents]*/
Show_vents=false;
Vent_width=12;//[1:.01:10]
Vent_number=6;//[3:1:6]

/*[Hidden]*/
$fn=100;
//$fa=$preview? 2:.1;;
//$fs=$preview?.1:.1;;

module cap(){
rotate_extrude(360){
 translate([Cap_diameter/2,4,0])
 circle(wall_thickness-3);
 translate([Cap_diameter/2,4,0])
 square([wall_thickness,Cap_height]);
}
for(i=[1:Ridge_number])
 rotate([0,0,i*360/Ridge_number])
rotate_extrude(Ridge_width){
 translate([Cap_diameter/2+wall_thickness,6,0])
 circle(Ridge_depth);
 translate([Cap_diameter/2+wall_thickness,4,0])
 square([Ridge_depth,Cap_height]);
}}

module center_hole(){
translate([0,0,1])
difference(){
 cylinder(h=Thickness,r=Cap_diameter/2+wall_thickness);
 translate([0,0,-1])
 cylinder(h=Thickness*2,r=Hole_size/2);
}}

module thread_vents(){
if(Show_vents)
for(i=[1:Vent_number]){
 rotate([0,0,i*360/Vent_number])
rotate_extrude(Vent_width){
 translate([Cap_diameter/2-4,4,0])
 circle(4.20);
 translate([Cap_diameter/2-4.2,4,0])
 square([7.20,Cap_height]);
}}}

module Threads(){
 translate([0,0,3.5])
for (i =[0:.5:Tn-80]){
hull(){
 translate([Cap_diameter/2*cos(i*Pitch_angle/Tn),Cap_diameter/2*sin(i*Pitch_angle/Tn),Cap_height*(i/Tn)])
    rotate(a=180+(i*(Pitch_angle/Tn)),v=[0,0,.1])
    rotate(a=90,v=[.1,0,0])
    sphere(Thread_thickness,$fn=Thread_shape);
 translate([Cap_diameter/2*cos((i+1)*Pitch_angle/Tn),Cap_diameter/2*sin((i+1)*Pitch_angle/Tn),Cap_height*(i+1)/Tn])
    rotate(a=180+(i*(Pitch_angle/Tn)),v=[0,0,.1])
    rotate(a=90,v=[.1,0,0])
    sphere(Thread_thickness,$fn=Thread_shape);
 translate([Cap_diameter/2*cos(i*Pitch_angle/Tn),Cap_diameter/2*sin(i*Pitch_angle/Tn),Cap_height*(i/Tn)])
    sphere(Thread_thickness/3,$fn=Thread_shape);
}}}

cap();
center_hole();

difference(){
Threads();
thread_vents();
}
 

And here are some examples:

I will probably add the ability to make the threads a bit deeper to get more bite if I find the cap is leaking, I will need to make some test prints....