3D part design with OpenScad #24-Adding text capabilities to the pipe fitting module

5 min read
By Bob
3D part design with OpenScad #24-Adding text capabilities to the pipe fitting module

I wanted to be able to mark the size of the different branches,so I added the capability to the pipe fitting module:

I added a text input to each of the existing branches,then set up a "text" module:

Just copy and paste the revised code into the editor pane in OpenScad:

(Update 6/4/2022, the text wasn't moving with the branches  when rotate all was used, I fixed it by adding  rotate all for  x,y and z in the text sections and now the text moves properly)

/* [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;
ShowText1 = true;
Text1 = "1";
Font_Style1 = "";
TextSize1= 2; //[.1:0.01:4]
angleX_branch1 = 0; //[-360:0.01:360]
angleY_branch1 = 0; //[-360:0.01:360]
angleZ_branch1 = 0; //[-360:0.01:360]
outside_diameter1 = 6;//[2:0.01:50]
inside_diameter1= 4; //[0:0.01:49]
length1 = 12; //[0:0.01:200]
outside_shape1 = 100; //[3:1:100]
inside_shape1 = 100; //[3:1:100]

/* [Branch 2] */
Show_branch2 = true;
ShowText2 = true;
Text2 = "2";
Font_Style2 = "";
TextSize2= 2; //[.1:0.01:4]
angleX_branch2 = 90; //[-360:0.01:360]
angleY_branch2 = 0; //[-360:0.01:360]
angleZ_branch2 = 0; //[-360:0.01:360]
outside_diameter2 = 6;//[2:0.01:50]
inside_diameter2= 4; //[0:0.01:49]
length2 = 12; //[0:0.01:200]
outside_shape2 = 100; //[3:1:100]
inside_shape2 = 100; //[3:1:100]

/* [Branch 3] */
Show_branch3 = true;
ShowText3 = true;
Text3 = "3";
Font_Style3 = "";
TextSize3= 2; //[.1:0.01:4]
angleX_branch3 = 270; //[-360:0.01:360]
angleY_branch3 = 180; //[-360:0.01:360]
angleZ_branch3 = 0; //[-360:0.01:360]
outside_diameter3 = 6;//[2:0.01:50]
inside_diameter3= 4; //[0:0.01:49]
length3 = 12; //[0:0.01:200]
outside_shape3 = 100; //[3:1:100]
inside_shape3 = 100; //[3:1:100]

/* [Branch 4] */
Show_branch4 = true;
ShowText4 = true;
Text4 = "4";
Font_Style4 = "";
TextSize4= 2; //[.1:0.01:4]
text4_height=1; //[.1:0.01:40]
angleX_branch4 = 180; //[-360:0.01:360]
angleY_branch4 = 0; //[-360:0.01:360]
angleZ_branch4 = 180; //[-360:0.01:360]
outside_diameter4 = 6;//[2:0.01:50]
inside_diameter4= 4; //[0:0.01:49]
length4 = 12; //[0:0.01:200]
outside_shape4 = 100; //[3:1:100]
inside_shape4 = 100; //[3:1:100]

/* [Branch 5] */
Show_branch5 = true;
ShowText5 = true;
Text5 = "5";
Font_Style5 = "";
TextSize5= 2; //[.1:0.01:4]
angleX_branch5 = 0; //[-360:0.01:360]
angleY_branch5 = 90; //[-360:0.01:360]
angleZ_branch5 = 0; //[-360:0.01:360]
outside_diameter5 = 6;//[2:0.01:50]
inside_diameter5= 4; //[0:0.01:49]
length5 = 12; //[0:0.01:200]
outside_shape5 = 100; //[3:1:100]
inside_shape5 = 100; //[3:1:100]

/* [Branch 6] */
Show_branch6 = true;
ShowText6 = true;
Text6 = "6";
Font_Style6 = "";
TextSize6= 2; //[.1:0.01:4]
angleX_branch6 = 0; //[-360:0.01:360]
angleY_branch6 = 270; //[-360:0.01:360]
angleZ_branch6 = 0; //[-360:0.01:360]
outside_diameter6 = 6;//[2:0.01:50]
inside_diameter6= 4; //[0:0.01:49]
length6 = 12; //[0: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])
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])
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])
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])
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])
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])
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);
}
//
module Text(){
if (ShowText1)
color("red")
rotate([Rotate_all_X,Rotate_all_Y,Rotate_all_Z])
rotate([angleX_branch1,angleY_branch1,angleZ_branch1])
translate([0,inside_diameter1/2,center_diameter])
rotate([90,0,180])
linear_extrude(height=(outside_diameter1-inside_diameter1)/1.9)
text(Text1,font=Font_Style1,TextSize1,halign = "center",valign = "bottom",spacing = 1,direction="ltr", $fn=100);

if (ShowText2)
color("red")
rotate([Rotate_all_X,Rotate_all_Y,Rotate_all_Z])
rotate([angleX_branch2,angleY_branch2,angleZ_branch2])
translate([0,inside_diameter2/2,center_diameter])
rotate([90,0,180])
linear_extrude(height=(outside_diameter2-inside_diameter2)/1.9)
text(Text2,font=Font_Style2,TextSize2,halign = "center",valign = "bottom",spacing = 1,direction="ltr", $fn=100);

if (ShowText3)
color("red")
rotate([Rotate_all_X,Rotate_all_Y,Rotate_all_Z])
rotate([angleX_branch3,angleY_branch3,angleZ_branch3])
translate([0,inside_diameter3/2,center_diameter])
rotate([90,0,180])
linear_extrude(height=(outside_diameter3-inside_diameter3)/1.9)
text(Text3,font=Font_Style3,TextSize3,halign = "center",valign = "bottom",spacing = 1,direction="ltr", $fn=100);

if (ShowText4)
color("red")
rotate([Rotate_all_X,Rotate_all_Y,Rotate_all_Z])
rotate([angleX_branch4,angleY_branch4,angleZ_branch4])
translate([0,inside_diameter4/2,center_diameter])
rotate([90,0,180])
linear_extrude(height=(outside_diameter4-inside_diameter4)/1.9)
text(Text4,font=Font_Style4,TextSize4,halign = "center",valign = "bottom",spacing = 1,direction="ltr", $fn=100);

if (ShowText5)
color("red")
rotate([Rotate_all_X,Rotate_all_Y,Rotate_all_Z])
rotate([angleX_branch5,angleY_branch5,angleZ_branch5])
translate([0,inside_diameter5/2,center_diameter])
rotate([90,0,180])
linear_extrude(height=(outside_diameter5-inside_diameter5)/1.9)
text(Text5,font=Font_Style5,TextSize5,halign = "center",valign = "bottom",spacing = 1,direction="ltr", $fn=100);

if (ShowText6)
color("red")
rotate([Rotate_all_X,Rotate_all_Y,Rotate_all_Z])
rotate([angleX_branch6,angleY_branch6,angleZ_branch6])
translate([0,inside_diameter6/2,center_diameter])
rotate([90,0,180])
linear_extrude(height=(outside_diameter6-inside_diameter6)/1.9)
text(Text6,font=Font_Style6,TextSize6,halign = "center",valign = "bottom",spacing = 1,direction="ltr", $fn=100);

}

if (Show_fitting){

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

If you want the lettering to be recessed instead of raised just comment out the module call and enable it in the difference section:

If you want to change the direction of the text just change "ltr"(left to right) to "ttb"(top to bottom):