How to Create Letter Molds and Stamps for 3D Printing on OpenScad
Tags: beginners, tutorial, 3dprinting, openscad
Published: 2020-03-21 17:50:45

---
title: How to Create Letter Molds and Stamps for 3D Printing on OpenScad
published: true
description: OpenScad is a free and open source CAD software available for Linux, Windows and Mac. The big deal is that with OpenScad you use code to create solid 3D CAD objects. In this tutorial, we'll see how to create simple molds / stamps using OpenScad.
tags: beginners, tutorial, 3dprinting, openscad
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/chv1pv7tu61xbtx9ue4q.png
---

In these times of social isolation and quarantine, we're doing everything we can to entertain our kids and have a few moments of peace in the household. For some of us who are lucky enough to have a 3D printer at home right now, there are [quite a few cool little projects](https://www.myminifactory.com/category/Young-Children) that can be downloaded for free and printed at home.

If you are anything like me, however, you might feel the itch to create your own models, just because.. you can? 

I wanted to create some simple play-dough molds to play with my 3 year old daughter this weekend, and while it's not hard to find such models for download out there, I always feel fascinated by using code to create 3D models and bring them to life with my printer. So that's how I chose to spend my Saturday morning today - messing around with [OpenScad](https://www.openscad.org/). This mold also doubles as stamp, if you use a string instead of single letter when printing it out.

{% tweet 1241358959530950657 %}

## OpenScad Overview

[OpenScad](https://www.openscad.org/) is a free and open source CAD software available for Linux, Windows and Mac. The big deal is that with OpenScad you use **code** to create solid 3D CAD objects.

If you are familiar with image manipulation and transformation via code, you might find that OpenScad is quite straightforward, once you see a few different examples and get used to its syntax (which actually resembles a lot PHP, so another reason why I liked it).

The software comes with many examples that you can try out to get familiar with the built-in API. You can find this under the menu `File` -> `Examples`.

![OpenScad overview](https://dev-to-uploads.s3.amazonaws.com/i/03ym8guk0kkejflnfdfu.png)

A handy cheat sheet is available under the menu `Help` -> `Cheat Sheet`.

### Creating 3D Text with OpenScad

In OpenScad, you have different functions that can create 3D shapes such as cubes and spheres, but it is typical to create 3D shapes and then use the `linear_extrude` function to turn them into 3D objects. This is how you write text.

The following code creates a 3D text:

```php
font = "DejaVu Sans:style=Bold";
letter_size = 40;
height = 10;
string = "DEV";

linear_extrude(height) {
    text(string, size = letter_size, font = font, halign = "center", valign = "center", $fn = 64);
}
```

You may need to change the font to a font supported by your system. Check the OpenScad menu `Help` -> `Font List` for a list of available fonts.

The preview window will show the following:

![Simple Text Preview](https://dev-to-uploads.s3.amazonaws.com/i/rpw2od0p7cgh5o9kdawh.png)

If you were to print this as is, you would get 3 separate letters. You could use a rectangle as base to print the text as a unique piece, like a nametag. For that, you'd want to use the `union` function:

```php
font = "DejaVu Sans:style=Bold";
letter_size = 40;
height = 10;

string = "DEV";
textlen = len(string);

box_width = letter_size*textlen*1.1;
box_height = letter_size*1.5;

union() {
    linear_extrude(1) {
        square([box_width, box_height], center = true);
    }
    
    linear_extrude(height) {
        text(string, size = letter_size, font = font, halign = "center", valign = "center", $fn = 64);
    }
}

```

This code will give you the following object:

![Embossed Text](https://dev-to-uploads.s3.amazonaws.com/i/cjw99vfqugque91s8sru.png)

Now, suppose you'd like an inverted effect, like a stencil. Instead of `union`, you'd use `difference` in this case:

```php
font = "DejaVu Sans:style=Bold";
letter_size = 40;
height = 10;

string = "DEV";
textlen = len(string);

box_width = letter_size*textlen*1.1;
box_height = letter_size*1.5;

difference() {
    linear_extrude(height) {
        square([box_width, box_height], center = true);
    }
    
    linear_extrude(height) {
        text(string, size = letter_size, font = font, halign = "center", valign = "center", $fn = 64);
    }
}
```
This code will give you the following object:

![Inverted text](https://dev-to-uploads.s3.amazonaws.com/i/t4bz6vt3umuwn0cceizh.png)

If you want to turn this into a mold or cookie cutter thou, you'd like to have only the outline of the letters, instead of a full "background". For that, we can use the `offset` function. To create an outline, we use two different offsets on top of the same 2D drawing; this 2D outline can then be extruded. The following example creates an outline for the specified text:

```php
font = "DejaVu Sans:style=Bold";
letter_size = 40;
height = 10;

string = "DEV";
textlen = len(string);

linear_extrude(height) {
    difference() {
        offset(r=-1) {
            text(string, size = letter_size, font = font, halign = "center", valign = "center", $fn = 64);
        }
    
        offset(r=-2) {
            text(string, size = letter_size, font = font, halign = "center", valign = "center", $fn = 64);
       }
    }
}
```

This will give you the following object:

![stamp without base](https://dev-to-uploads.s3.amazonaws.com/i/ekn0cr52k5uece7gz59n.png)

Although this looks ok, you'd need something to "hold" the insides of some letters in place, like it's the case with the letter "D" in this example. We can place a rectangle base on **top** of the letter then, to make sure you won't get a mirrored effect when cutting the dough with this mold. 

The final code rearranges things a bit and creates a few *modules* (this works like a function) to avoid duplicating the same piece of code as we've done before with the text. This will create a nice cookie/dough cutter that also doubles as stamp, and you can customize as desired.

{% gist https://gist.github.com/erikaheidi/e0149417fea7bd29cd338f9b56d32e31 %}

Result:

![Final result](https://dev-to-uploads.s3.amazonaws.com/i/chv1pv7tu61xbtx9ue4q.png)

I hope you have enjoyed this short OpenScad tutorial! If you have any questions, feel free to leave a comment ;)