3D part design with OpenSCAD #83: Bending text part 2.

Some improvements to the bend text module for OpenSCAD from the last post.

3 min read
By Bob
3D part design with OpenSCAD #83: Bending text part 2.

It was pretty easy to change the direction the text bends with a couple of rotate commands.

I highly recommend using the latest OpenSCAD development build, scroll down to development snapshots:

OpenSCAD - Downloads

here is the updated code:

/*[Bend Text]*/
Input_text="Text";
Font_style="";
direction="ltr"; // [ttb,btt,rtl]
text_size=30;//[2:1:60]
text_spacing=1;//[.1:.01:10]
text_extrude=.5;//[.1:.01:5]
bend=113.5;//[-360:.01:360]
tilt_angle=0;//[0:.01:180]
rotate_x=90;//[0:.01:360]
rotate_y=90;//[0:.01:360]
rotate_z=0;//[0:.01:360]
move_x=0;//[-400:.01:400]
move_y=0;//[-400:.01:400]
move_z=0;//[-400:.01:400]

/*[Clip Area]*/
show_clip_area=false;
steps=100;//[3:1:200]
clip_height=400;//[1:.1:400]
clip_width=100;//[5:.1:400]

dh=clip_width/steps;
r=clip_width/(bend*PI/180);
h0=-clip_width/2;

module bend_text(){
  translate([0,0,-r])
  rotate([bend/2,0,0])
  render()
for(i=[0:.7:steps]){
  rotate([-i*bend/steps,0,0])
  translate([0,-(dh*i+h0),r])
intersection() {
  rotate([0,0,90])
  rotate(a=tilt_angle,v=[0,0,90])
  linear_extrude(text_extrude)
  text(Input_text,font=Font_style,spacing=text_spacing,size=text_size,valign="center",halign="center",direction=direction,$fn=60);
 translate([0,dh*i+h0,0]) 
 rotate([0,90,0])
 rotate(a=tilt_angle,v=[0,20,0])
 cube([clip_width,dh,clip_height],center=true);
 if(show_clip_area)
 translate([0,dh*i+h0,0]) 
 rotate([0,90,0])
 rotate(a=tilt_angle,v=[0,0,90])
 #cube([clip_width,dh,clip_height],center=true);
}}}



rotate([rotate_x,rotate_y,rotate_z])
translate([-move_z,move_x,-move_y])
bend_text();

By adding a "tilt angle I was able to make the text bendable in any direction:

The clip area is to resize the bend area to fit the size of the text, I tried fontmetrics() and couldn't get it to work with different fonts. I wanted to size the area automatically with any font style, but doing it manually works fine. If you want the text to wrap all the way around 360 degrees set bend to 360 and adjust the clip width until the ends touch but it doesn't clip the text.

I also added a selector to change the orientation of the text form left to right, right to left, bottom to top and top to bottom for different situations: