3D part design with OpenScad #23 unlimited pipe fitting module

4 min read
By Bob
3D part design with OpenScad #23 unlimited pipe fitting module

This module is for making pipe fittings, you can add branches, adjust each branch angle, branch inside and outside shape, length and diameter.

Here is the code, just copy and paste it into the editor in OpenScad:

/* [Pipe Fitting] */
Show_fitting = true;
center_diameter = 6;//[3:0.01:50]
center_shape = 100; //[3:1:100]
Rotate_all_X = 0; //[-360:0.01:360]
Rotate_all_Y = 0; //[-360:0.01:360]
Rotate_all_Z = 0; //[-360:0.01:360]

/* [Branch 1] */
Show_branch1 = true;
angleX_branch1 = 0; //[0:0.01:360]
angleY_branch1 = 0; //[0:0.01:360]
angleZ_branch1 = 0; //[0:0.01:360]
Rotate_branch1_Z = 0; //[0:0.01:360]
outside_diameter1 = 6;//[2:0.01:50]
inside_diameter1= 4; //[0:0.01:49]
length1 = 12; //[8:0.01:200]
outside_shape1 = 100; //[3:1:100]
inside_shape1 = 100; //[3:1:100]

/* [Branch 2] */
Show_branch2 = true;
angleX_branch2 = 90; //[0:0.01:360]
angleY_branch2 = 0; //[0:0.01:360]
angleZ_branch2 = 0; //[0:0.01:360]
Rotate_branch2_Z = 0; //[0:0.01:360]
outside_diameter2 = 6;//[2:0.01:50]
inside_diameter2= 4; //[0:0.01:49]
length2 = 12; //[8:0.01:200]
outside_shape2 = 100; //[3:1:100]
inside_shape2 = 100; //[3:1:100]

/* [Branch 3] */
Show_branch3 = true;
angleX_branch3 = 270; //[0:0.01:360]
angleY_branch3 = 0; //[0:0.01:360]
angleZ_branch3 = 0; //[0:0.01:360]
Rotate_branch3_Z = 0; //[0:0.01:360]
outside_diameter3 = 6;//[2:0.01:50]
inside_diameter3= 4; //[0:0.01:49]
length3 = 12; //[8:0.01:200]
outside_shape3 = 100; //[3:1:100]
inside_shape3 = 100; //[3:1:100]

/* [Branch 4] */
Show_branch4 = true;
angleX_branch4 = 180; //[0:0.01:360]
angleY_branch4 = 0; //[0:0.01:360]
angleZ_branch4 = 0; //[0:0.01:360]
Rotate_branch4_Z = 0; //[0:0.01:360]
outside_diameter4 = 6;//[2:0.01:50]
inside_diameter4= 4; //[0:0.01:49]
length4 = 12; //[8:0.01:200]
outside_shape4 = 100; //[3:1:100]
inside_shape4 = 100; //[3:1:100]

/* [Branch 5] */
Show_branch5 = true;
angleX_branch5 = 0; //[0:0.01:360]
angleY_branch5 = 90; //[0:0.01:360]
angleZ_branch5 = 0; //[0:0.01:360]
Rotate_branch5_Z = 0; //[0:0.01:360]
outside_diameter5 = 6;//[2:0.01:50]
inside_diameter5= 4; //[0:0.01:49]
length5 = 12; //[8:0.01:200]
outside_shape5 = 100; //[3:1:100]
inside_shape5 = 100; //[3:1:100]

/* [Branch 6] */
Show_branch6 = true;
angleX_branch6 = 0; //[0:0.01:360]
angleY_branch6 = 270; //[0:0.01:360]
angleZ_branch6 = 0; //[0:0.01:360]
Rotate_branch6_Z = 0; //[0:0.01:360]
outside_diameter6 = 6;//[2:0.01:50]
inside_diameter6= 4; //[0:0.01:49]
length6 = 12; //[8:0.01:200]
outside_shape6 = 100; //[3:1:100]
inside_shape6 = 100; //[3:1:100]

module fitting_outside(){

if (Show_branch1)
rotate([Rotate_all_X,Rotate_all_Y,Rotate_all_Z])
rotate([angleX_branch1,angleY_branch1,angleZ_branch1])
rotate([0,0,Rotate_branch1_Z])
cylinder(h=length1,r1=outside_diameter1/2,r2=outside_diameter1/2,center=false,$fn=outside_shape1);
if (Show_branch2)
rotate([Rotate_all_X,Rotate_all_Y,Rotate_all_Z])
rotate([angleX_branch2,angleY_branch2,angleZ_branch2])
rotate([0,0,Rotate_branch2_Z])
cylinder(h=length2,r1=outside_diameter2/2,r2=outside_diameter2/2,center=false,$fn=outside_shape2);
if (Show_branch3)
rotate([Rotate_all_X,Rotate_all_Y,Rotate_all_Z])
rotate([angleX_branch3,angleY_branch3,angleZ_branch3])
rotate([0,0,Rotate_branch3_Z])
cylinder(h=length3,r1=outside_diameter3/2,r2=outside_diameter3/2,center=false,$fn=outside_shape3);
if (Show_branch4)
rotate([Rotate_all_X,Rotate_all_Y,Rotate_all_Z])
rotate([angleX_branch4,angleY_branch4,angleZ_branch4])
rotate([0,0,Rotate_branch4_Z])
cylinder(h=length4,r1=outside_diameter4/2,r2=outside_diameter4/2,center=false,$fn=outside_shape4);
if (Show_branch5)
rotate([Rotate_all_X,Rotate_all_Y,Rotate_all_Z])
rotate([angleX_branch5,angleY_branch5,angleZ_branch5])
rotate([0,0,Rotate_branch5_Z])
cylinder(h=length5,r1=outside_diameter5/2,r2=outside_diameter5/2,center=false,$fn=outside_shape5);
if (Show_branch6)
rotate([Rotate_all_X,Rotate_all_Y,Rotate_all_Z])
rotate([angleX_branch6,angleY_branch6,angleZ_branch6])
rotate([0,0,Rotate_branch6_Z])
cylinder(h=length6,r1=outside_diameter6/2,r2=outside_diameter6/2,center=false,$fn=outside_shape6);
}
//
module fitting_inside(){

if (Show_branch1)
rotate([Rotate_all_X,Rotate_all_Y,Rotate_all_Z])
rotate([angleX_branch1,angleY_branch1,angleZ_branch1])
cylinder(h=length1+1,r1=inside_diameter1/2,r2=inside_diameter1/2,center=false,$fn=inside_shape1);
if (Show_branch2)
rotate([Rotate_all_X,Rotate_all_Y,Rotate_all_Z])
rotate([angleX_branch2,angleY_branch2,angleZ_branch2])
cylinder(h=length2+1,r1=inside_diameter2/2,r2=inside_diameter2/2,center=false,$fn=inside_shape2);
if (Show_branch3)
rotate([Rotate_all_X,Rotate_all_Y,Rotate_all_Z])
rotate([angleX_branch3,angleY_branch3,angleZ_branch3])
cylinder(h=length3+1,r1=inside_diameter3/2,r2=inside_diameter3/2,center=false,$fn=inside_shape3);
if (Show_branch4)
rotate([Rotate_all_X,Rotate_all_Y,Rotate_all_Z])
rotate([angleX_branch4,angleY_branch4,angleZ_branch4])
cylinder(h=length4+1,r1=inside_diameter4/2,r2=inside_diameter4/2,center=false,$fn=inside_shape4);
if (Show_branch5)
rotate([Rotate_all_X,Rotate_all_Y,Rotate_all_Z])
rotate([angleX_branch5,angleY_branch5,angleZ_branch5])
cylinder(h=length5+1,r1=inside_diameter5/2,r2=inside_diameter5/2,center=false,$fn=inside_shape5);
if (Show_branch6)
rotate([Rotate_all_X,Rotate_all_Y,Rotate_all_Z])
rotate([angleX_branch6,angleY_branch6,angleZ_branch6])
cylinder(h=length6+1,r1=inside_diameter6/2,r2=inside_diameter6/2,center=false,$fn=inside_shape6);
}
//

if (Show_fitting){
difference(){
sphere(center_diameter,$fn=center_shape);
fitting_inside();
}
difference(){
fitting_outside();
fitting_inside();
}}
//

You can add branches by simply copying and pasting one of the other branches and changing the number to the next one in line.