Contents
- Learning Objectives
- Introducing the Text Primitive in OpenSCAD
- Modifying Text Properties
- Text Alignment Parameters
- Text Direction
- Combining Text with Other Primitives
- Practice Exercises
Learning Objectives
At the end of this lesson, you will be able to:
- Use the text primitive in OpenSCAD.
- Adjust the size and font of text.
- Understand and modify the alignment parameters of text.
- Manipulate the direction of text.
- Combine text with other primitives.
Introducing the Text Primitive in OpenSCAD
The text primitive in OpenSCAD enables the creation of 2D text. Its only required parameter is an input string. For example:
text("hello world");
You can adjust this input string to any text you want, such as your name.
Modifying Text Properties
The text primitive accepts a size parameter, which defines the height of the tallest letter. For instance:
text("hello", size=20);
Additionally, you can select different fonts via the font
parameter. The available fonts can be accessed from the Help > Font list (Alt > H > F) in OpenSCAD. For instance:
text("hello", size=20, font="agency fb");
Text Alignment Parameters
Text in OpenSCAD can also have alignment parameters: halign
and valign
.
halign
adjusts horizontal alignment and accepts “left”, “center”, or “right”, with the default being “left”.valign
adjusts vertical alignment and accepts “top”, “center”, “baseline”, or “bottom”, with the default being “baseline”.
For example:
text("hello", size=20, halign="center", valign="center");
Text Direction
The direction
parameter in the text primitive specifies the flow of text. Options include “ltr” (left-to-right), “rtl” (right-to-left), “ttb” (top-to-bottom) and “btt” (bottom-to-top), with the default being “ltr”. Here is an example:
text("hello", size=20, halign="center", valign="center", direction="ttb");
Combining Text with Other Primitives
OpenSCAD’s transformation and Boolean operators also work with the text primitive. For example:
difference(){
circle(d=20);
text("hello",halign="center",valign="center",size=4);
}
Note: The width of your text depends on the font size and direction. A rough estimation is that it’s the size value multiplied by the number of characters in your string.
Practice Exercises
Now, practice what you’ve learned with these exercises:
- Using a non-default font, create a 2D keychain with your name on it.
- Design a 2D keychain with vertically oriented text (reading