1
$\begingroup$

I'm needing to generate a set of different texts each in their own font so that I can see which one would look best, something like this (have a whole bunch of fonts do do this with).

Wanted

I created a short test script, which when ran it ends up looking like this.

enter image description here

Here's the script, each individual text works when ran alone, but they won't work if all texts are generated. Any ideas why it won't work? Probably something simple I'm overlooking.

import bpy

bpy.ops.object.text_add(location=(0, 0, 0), rotation=(0, 0, 0))
txt = bpy.data.objects['Text']
txt.data.body = 'Brush Script'
fnt = bpy.data.fonts.load('/Library/Fonts/Brush Script.ttf')
txt.data.font = fnt

bpy.ops.object.text_add(location=(0, 1, 0), rotation=(0, 0, 0))
txt1 = bpy.data.objects['Text']
txt1.data.body = 'Chalkboard'
fnt = bpy.data.fonts.load('/Library/Fonts/Chalkboard.ttc')
txt1.data.font = fnt

bpy.ops.object.text_add(location=(0, 2, 0), rotation=(0, 0, 0))
txt2 = bpy.data.objects['Text']
txt2.data.body = 'Chalkduster'
fnt = bpy.data.fonts.load('/Library/Fonts/Chalkduster.ttf')
xt2.data.font = fnt
$\endgroup$
1
$\begingroup$

Quick example of all fonts in a directory. I'm sure someone else can improve the coding for optimization.

import bpy
from os import listdir
from os.path import isfile, join

mypath = 'G:\\Blender Working folders\\Fonts'  # your font directory

onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))]
count = 0
for f in onlyfiles:
    bpy.ops.object.text_add(location=(0, count, 0))
    txt = bpy.context.active_object
    txt.data.body = f
    fnt = bpy.data.fonts.load(join(mypath, f))
    txt.data.font = fnt
    count += 1
$\endgroup$
  • $\begingroup$ Thanks, that worked with a few changes, as I'm using a mac $\endgroup$ – gwfami Nov 30 '18 at 5:12
  • $\begingroup$ import bpy from os import listdir from os.path import isfile, join mypath = '/Library/Fonts/' # your font directory onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))] count = 0 print (onlyfiles) for f in onlyfiles: if f.endswith('.ttf') or f.endswith('.TTF') or f.endswith('.otf'): bpy.ops.object.text_add(location=(0, count, 0)) txt = bpy.context.active_object txt.data.body = f fnt = bpy.data.fonts.load(join(mypath, f)) txt.data.font = fnt count += 1 $\endgroup$ – gwfami Nov 30 '18 at 5:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.