text() – text command tutorial

As of OpenSCAD 2019 text has gotten a lot easier to add in OpenSCAD. Basic text can be added with just the bare Command:

text( "Basic Text" );

This command can be translated and rotated just liky any other object in OpenSCAD, but keep in mind it is 2d first and needs to be extruded.

linear_extrude()
text( "Extruded Text");

So the defaults for size are 10 for text size and 100 for linear_extrude let’s fix that by giving some sizes.

linear_extrude(3)
text( "Extruded Text", size= 5);

The text is now 5 Units Tall, and it is extruded 3 units in thickness

Using Different Fonts

We can change the Font Type using the Font keyword.

OpenSCAD can use any of the system fonts found in the installation. To make it easier to use a font stlye you can list fonts from the Help menu.

Click Help-Font List to get this list:

Select the font you would like to use and click “Copy to The Clipboard” This will copy the Font and Style in the correctly formatted string.

linear_extrude( 1)
text( "Text",size=5,font="Uechi:style=Gothic" , $fn=50);

Changing Orientation

We can place text into various orientation, by using the direction keyword. There are four directions we can organize lettering.

text( "Left to Right" ,size=5, direction="ltr");
translate([5,0,0])
text( "Up" ,size=5, direction="btt");
translate([20,0,0])
text( "Down" ,size=5, direction="ttb");
translate([0,10,0])
text( "Right to left" ,size=5, direction="rtt");

Adding Horizontal Alignment

Horizontal alignment is in regard to to origin and the bounding box of the text. It is best explained visual. Take note of where the origin is for each alignment. The alignment is by length of the rendered text NOT by character count.

text( "Left Aligned" ,halign = "left" );
text( "Right Aligned" ,halign = "right" );
text( "Center Aligned" ,halign = "center" );

Below you can see the 3 vertical alignments. The alignment refers to were origin will align with the text.

text( "Text", valign="top");
text( "Text", valign="center");
text( "Text", valign="bottom");
top

center

botton

There are a few more options for Text in OpenSCAD but the above are the ones you will use the most.

3 Replies to “text() – text command tutorial”

  1. Bernie Goldberg

    How do you set the color of the text?
    I tried doing this:

    color(“red”) text(text3,direction=”ltr”,size=textsizeA);

    but that does not seem to work.

    Any suggestions would be appreciated.

    • admin

      Your color command is correct.

      This code works:
      text3 = "Some Text";
      textsizeA = 10;

      color("red")
      text(text3,direction="ltr",size=textsizeA);

      Do you have values in the variables you are using?

      Perhaps there is an error elsewhere ( preceding the color command. )
      Perhaps, try the code alone in a new design.

  2. SaKhepra

    After playing around with text color in OpenSCAD, it appears the color() function does not work, when its sequential logical execution order, as an OpenSCAD command, follows certain other function operators [ e.g. linear extrusion() ].

    For me, placing the color() function, preceding the logical execution function() of my text() made it work, without needing to define my desired text inside a variable, to later be used inside the text () function.

    This same condition holds true for other OpenSCAD logical execution scenarios dealing with color (especially using 2D & 3D functions), as it appears OpenSCAD considers color() a “Transformation” function type, similar to the translate() function and linear_extrude(), a “3D” function type, similar to the sphere() function.

    That said, the same thing happens (i.e. the OpenSCAD logic will not work), when the color() or translate() function is placed after either the text() or sphere() functions, as text is a 2D function and sphere is a 3D function. Whereas it does not matter the sequence of when the color() function and translate() functions are declared in relation to each other, since they are both transform functions, as long as they both precede any 2D (text, circle, etc.) functions and/or 3D (cube, linear_extrude, etc.) functions. Am a newbie to OpenSCAD, but believe if you follow these rules, you should be good to go.

    Hoping that helps! 🙂

    P.S. Big Thanks @ Admin for demonstrating how to assign variables that can be used in a text() function @ very helpful!!! Your code initially solved my issue of the color() and text() functions not displaying color, until I started manipulating my text with additional functions. Also just want to say, I truly appreciate this website, as am just getting started with OpenSCAD, and find it to be a very valuable learning resource.

    Cheers,
    SaKhepra

Leave a Reply

Your email address will not be published. Required fields are marked *