[Python] Retrieve width of text object

Does anyone know if it’s possible to get the width of a text object with python?

I’m creating my speech system and at first I had 75 characters per line, but each character has a different width so sentences did not fit well. If I could get the ‘width’ of a text variable then I’d be sorted. Anyone know how?

Its probably a bit tricky with text objects.

You can find the largest letter, perhaps m or w, and see how many times that fits into a line and make that the limit.

just as andrew-101 said:
you make the text full of WWWWWWW, scale it around until it fits and then make some lines of this. This has a downside and that would be that most of the time you dont have
any lines that contain WWWWMMM and because of that your text would always have
alot of space to the right.
I use this also, but wil watch this thread, mb somone has a better solution.
I mean i dont know how to do it to have it better but even msPaint has a better text box.

Ps: i dont know now where but here on the forum was a blend that hab the width of
some letters calculated, and saved in a dict. depending on the hit on the keyboard,
it moved respectivly. i will have a look after it.

EDIT: sry after an intense i couldnt fine the thread but i had the blend saved.
so here it is, it is NOT done by me! Maybe this can help you.

greets Equal

1 Like

If you feel up to some work, you could find the width of every character, save it to a dictionary, then in the text property find the width of every character and add them all up to find your total width.