3D keychains and cutting out the "whitespace" of text?
Back when I was doing woodworking, using a scrollsaw, I would cut 3D keychains with 2 words (usually first and last name). Basically you start out with a length of wood that is the same depth and height and tape a pattern of the words on the top and face of the block and cut out the wood AROUND the letters -- examples here and here.
Since I got my 3D printer I've been wanting to recreate these in plastic.
I can sort of SIMULATE the result of cutting the first word by creating a rectangle, cutting out a smaller version of the block and then putting in the text and extruding it:
This is comparable to creating an ambigram, although on two different axes
from the tutorial I found.
This tutorial <https://www.youtube.com/watch?v=baO1-HSodIs> uses Fusion
360 to create text in two planes by intersection, just as with the samples
of code provided in the posts here. The video is 26 minutes long.
I've used it with the hobbyist version of F360 and it works great, resulting
in a number of 3D printed gifts to friends and family.
I had often suspected that the same concepts could be applied to OpenSCAD.
One aspect of this process is that the text is "collected" along a diagonal
and joined to a base, rather than enclosed in a cage.
> The other problem is trying to figure out how long to make the block based
> on the size of the text/font...
You can get the bounding box of rendered text in PostScript (GhostScript)
and print it out. If you use the same font in both OpenSCAD and PostScript
and you scale the font to unity (or the same scale you use in OpenSCAD) in
Postscript you can have a very short PostScript program print out the length
for use in a shell script. I haven't tried this, but it seems it should
> You can get the bounding box of rendered text in PostScript (GhostScript)
> and print it out. If you use the same font in both OpenSCAD and PostScript
> and you scale the font to unity (or the same scale you use in OpenSCAD) in
> Postscript you can have a very short PostScript program print out the
> for use in a shell script. I haven't tried this, but it seems it should
Now I've looked into this I find that PostScript and OpenSCAD scale the
fonts differently. OpenSCAD scales them to a the height you specify and
PostScript seems to scale them to a line spacing. So making this work is not
so easy and you might have to tweak it for each font you use.
WOW! I was really only looking for some pointers, not expecting a complete
solution! Thank you! Now I just need to figure out what you've done... I
printed one out already -- not sure what's up with the stringing -- might
have do do some tuning to the printer or something, but other than that,
pretty good! Thanks again!
> Now I've looked into this I find that PostScript and OpenSCAD scale the
> fonts differently. OpenSCAD scales them to a the height you specify and
> PostScript seems to scale them to a line spacing. So making this work is
> so easy and you might have to tweak it for each font you use.
Now I've looked into it even further I've written a postscript file that
automatically finds the OpenSCAD scale for the specified font and then finds
the length of the specified string and prints it out:
/fn fn cvn def
fn findfont 1 scalefont setfont
0 0 moveto (yk) true charpath flattenpath pathbbox 1 exch div /fsf exch def
pop pop pop
fn findfont fsf scalefont setfont
is stringwidth pop ==
Name the above file OSsw.ps or choose your own name and and change the name
in the script below to what you choose. The length is for a text height of 1
so if you want a different height you'll have to scale what the above
produces accordingly however most convenient.
And here's a bash script as an example how to use it in a script:
# String for which length is wanted is first argument
# PostScript font name second argument
# Youll need quotes around a string with spaces.
# Both arguments are required.
# Run gs -sis=<string> -sfn=<FontName> OSsw.ps to check the font name.
# gs will default to it's own choice if it can't find yours and the message
# announcing that is suppressed in this script.
# On a system running fontconfig use fc-match -v to find the PostScript
# name of a font. Example:
# $ fc-match -v DeJaVuSans:style=oblique | grep postscriptname
# $ postscriptname: "DejaVuSans-Oblique"(w)
# Use OpenSCAD Hellp > Font List to get the pattern for fc-match
# Remove the spaces from the font name listed by OpenSCAD.
sw=`gs -q -dBATCH -dNOPAUSE -sis="$1" -sfn=$2 OSsw.ps`
echo The width of $1 in font $2 is $sw
# Now it is possible to construct an OpenSCAD command line to execute
# in a script similar to this one using $1, $2, and $sw