How to write all characters in a font to a 3D text object?

Can you help with inserting of all characters of a font (for example I loaded an Arial font) into 3D Text?

For example I created a 3D Text object and I need to insert all characters with Python:

All I found is how to insert a specific text:

bpy.ops.font.text_insert(text="texttt")


But I need all characters available in the font.

Also, can I separate characters by languages (english, french, spanish etc.) and other characters (,.<>[]{};:'" etc.)?

Thanks a lot!

• By the way, you can also use bpy.ops.object.text_add to add another text object. – wchargin Nov 10 '13 at 18:42

Well, it depends on what "all characters" are, but generally you should be able to just loop over a range of code points or character values, casting with chr.

For example, if you want all printable ASCII characters:

text_string = ''.join([chr(i) for i in range(32, 127)])
bpy.ops.font.text_insert(text=text_string)
# [SPACE]!"#\$%&\'()*+,-./0123456789:;<=>?@ABC...XYZ[\]^_abc...xyz{|}~


Here, I just used a list comprehension to go from ASCII 32 to ASCII 126, inclusive. You could use a different range to suit your needs.

You can't really "separate characters by languages" because it's not bijective. Which language does A belong to? Practically every language that uses a Latin-variant alphabet. How about ü? Spanish, German, to name two.

You could separate characters by their Unicode blocks, like Basic Latin (U+0000 to U+007F), Latin-1 Supplement (U+0080 to U+00FF, contains stuff like ¢, ©, §, õ, þ, etc.), etc.

For example, if you wanted two separate text objects:

blocks = { 'basic_latin' : (0x20, 0x7E), 'latin-1-supp': (0xA0, 0xFF) }
for k, v in blocks.items():
t = ''.join([chr(i) for i in range(v[0], v[1] + 1)])
bpy.ops.font.text_insert(text=t)

• Thank you a lot! It works like a charm! Small question: How to get hex characters of 'cyrilic' unicode block? I was looking here fileformat.info/info/unicode/block/cyrillic/index.htm But i have no good result. I used Arial.ttf which has Cyrilic block. Thank you. – mifth Nov 11 '13 at 10:57
• The result: # Latin text_string = ''.join([chr(i) for i in range(ord(u'\u0021'), ord(u'\u007E') + 1)]) bpy.ops.font.text_insert(text=text_string) # Cyrilic text_string = ''.join([chr(i) for i in range(ord(u'\u0410'), ord(u'\u044F') + 1)]) bpy.ops.font.text_insert(text=text_string) – mifth Nov 11 '13 at 15:10
• @mifth if the text isn't showing up properly, take a look at this question. – wchargin Nov 11 '13 at 15:26

The result:

Latin

text_string = ''.join([chr(i) for i in range(ord(u'\u0021'), ord(u'\u007E') + 1)])
bpy.ops.font.text_insert(text=text_string)


Cyrilic

text_string = ''.join([chr(i) for i in range(ord(u'\u0410'), ord(u'\u044F') + 1)])
bpy.ops.font.text_insert(text=text_string)
`