Python text box dimensions

When I set text object dimensions and insert the text by editing the object, it keeps the dimensions. However, when I set the text by inserting a string with python, the dimensions are ignored. Is that a matter of editing the object, or do I have to insert a python code to reorder the text columns and rows? I assign multiple strings to the text object.

The Blender Text object and the KX_FontObject are not the same. The KX_FontObject is … pretty simple. It shows some planes with font texture that is all. Do not expect a lot of nice-to-have options.

If you really need you wan write a proposal outlining what you want. A developer might pickup and implement what you suggest.

just now you can use string operations to format your text. If you use a proportional font you can’t tell the size of a text line.

That response goes a bit above my level. Would I use something like a .split() code? String operations as generic python code? Is there a setting to make text proportional? Sorry if my questions don’t make much sense.

Proportional font (like Arial) means that characters of a font do not have the same width e.g. the i is smaller then w.
Fixed fonts (Curier) have a fixed width. This allows to align characters in rows:
proportional:

A B C D
1 2 3 4

fixed:


A B C D
1 2 3 4

Currently there is nothing at the KX_FontObject that tells you the size of text it currently display.
Which means, you just know the number of characters not the over-all with.

You can easily calculate the length if you use a fixed size font: (length of string) * (width of a character)
You can determine the width of a single character before the game starts.


singleCharacterLength = # whatever you measure when the text has a single character only

displayString = cont.owner.text
displayStringLength = len( displayString ) 
fontObjectWidth = displayStringLength * singleCharacterLength

I hope it helps

Proportional font (like Arial) means that characters of a font do not have the same width e.g. the i is smaller then w.
Fixed fonts (Curier) have a fixed width. This allows to align characters in rows:
proportional:

A B C D E F G H I J K L M N O P Q
1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7

fixed:


A B C D E F G H I J K L M N O P Q
1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 

Currently there is nothing at the KX_FontObject that tells you the size of text it currently displays.
Which means, you just know the number of characters not the over-all width.

You can easily calculate the length if you use a fixed size font: (length of string) * (width of a character)
You can determine the width of a single character before the game starts.


singleCharacterLength = # whatever you measure when the text has a single character only

displayString = cont.owner.text
displayStringLength = len( displayString ) 
fontObjectWidth = displayStringLength * singleCharacterLength

I hope it helps

Yes, it does thanks. Could you answer another simple question? I was thinking in order to add string properties together I could just say own[‘string1’]=own[‘string2’] + " " + own[‘string2’] , but the program didn’t accept that code. Is there another way to do that?

Without the context of this code I can’t say. For that what you want it looks right.

Usually the exceptions tell you what Python does not like. I know it looks confusing at the first sight, but it really does.
I can only guess you get KeyError or TypeError.

Another way to format strings is using a format string:
… = “{} {}”.format(own[“string2”], own[“string2”])

Especially on larger strings and strings with more formatting/filler it offers much benefits.