FreeCAD Scripts for 3D-Printable Keyring Tags

3d-printing python freecad

I've been into 3D printing for a bit, and one of the most useful things I've made are personalized keyring tags. Instead of doing it manually each time, I built a Python script that generates them automatically in FreeCAD—perfect for batch jobs or one-offs.

The script is simple but flexible: you give it some text, and it generates a rounded-rectangle tag that auto-sizes its length to fit, adds a hole for the key ring, and exports everything as a 3MF file ready to slice and print.

The Script: Keyring Tag Generator

The main script—keyring_tag.py—does all the heavy lifting:

  • Auto-sizing: Tag length automatically scales based on text width, so "Alice" and "Christopher" both fit perfectly
  • Rounded corners: Softens the edges for a nicer print and handling
  • Built-in hole: A hole sized for standard key rings
  • CLI and GUI modes: Works headless (great for batch jobs) or as a FreeCAD macro
  • 3MF export: Exports directly to the format most slicers prefer

How I Use It

Headless mode (command line):

# Single tag
TAG="MyText" freecadcmd keyring_tag.py

# Custom output file
TAG="MyText" OUT="custom_output.3mf" freecadcmd keyring_tag.py

# Batch processing
for text in Alice Bob Charlie; do
  TAG="$text" freecadcmd keyring_tag.py
done

This is perfect when I want to generate a bunch of tags at once. I just loop through the names and let it rip.

GUI macro mode:

If you're more comfortable in FreeCAD's UI:

  1. Open FreeCAD
  2. Edit the TAG_TEXT variable in the script to your desired text
  3. Go to Macro → Execute Macro and select this file
  4. The output saves to ./keyrings/tag.3mf

Customization

The dimensions are all configurable. I keep them at the top of the script:

MIN_TAG_LENGTH = 30.0     # Minimum tag length in mm
TAG_WIDTH = 12.0          # Tag width in mm
TAG_THICK = 1.6           # Tag thickness in mm
CORNER_R = 3.0            # Rounded corner radius in mm
HOLE_DIA = 4.0            # Key ring hole diameter in mm
TEXT_SIZE = 6.0           # Font size in mm

Want thicker tags? Bigger text? Just tweak the numbers and regenerate.

Dependencies and Fonts

FreeCAD needs Python 3 support (tested with 0.19+) and access to a font. The script looks for:

  • DejaVu Sans (recommended, pre-installed on most Linux)
  • Liberation Sans
  • Free Sans
  • Arial / Helvetica (macOS/Windows)

Most systems have one of these already. Linux distros usually include DejaVu fonts by default, and system fonts are available on macOS and Windows.

Open Source

I threw this up on GitHub as an MIT-licensed project because it seemed useful enough to share. The code is straightforward—mostly FreeCAD API calls to create the geometry—so it's easy to fork and modify if you want different shapes or features.

The Output

Output files go into a keyrings/ subdirectory relative to the script:

FreeCadScripts/
├── keyring_tag.py
├── keyrings/
│   ├── alice.3mf
│   ├── bob.3mf
│   └── ...
└── README.md

I can then take those 3MF files straight to my slicer, adjust infill or support as needed, and print.

Why Automate This?

Manual CAD work for every tag gets old fast. With the script, I can generate a whole batch of customized tags in seconds, which is great for:

  • Personalized gifts - whip up a tag for whoever's coming over
  • Organization - label drawers, storage boxes, tool bags
  • Testing - quickly iterate on dimensions without the CAD tedium

It's one of those small automation wins that saves way more time than it took to build.

The repo is on GitHub if you want to use it or improve it...