5
$\begingroup$

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: Image of text object

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!

$\endgroup$
1
  • 1
    $\begingroup$ By the way, you can also use bpy.ops.object.text_add to add another text object. $\endgroup$
    – wchargin
    Nov 10, 2013 at 18:42

2 Answers 2

7
$\begingroup$

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:;<=>[email protected][\]^_`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)
$\endgroup$
3
  • $\begingroup$ 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. $\endgroup$
    – mifth
    Nov 11, 2013 at 10:57
  • $\begingroup$ 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) $\endgroup$
    – mifth
    Nov 11, 2013 at 15:10
  • $\begingroup$ @mifth if the text isn't showing up properly, take a look at this question. $\endgroup$
    – wchargin
    Nov 11, 2013 at 15:26
1
$\begingroup$

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)
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .