Hello, I was also wondering how to go about setting dynamic text and this thread helped me get started. I'm writing a program that takes in data from a file and displays it as a graph in maya and I'm using the text to display the numbers for the hash marks along the side and bottom of the graph. It's convoluted but I was able to write procedures to convert the numbers to hex and then use them to alter the text objects. However, there are two questions I have:
1) When creating these text objects they create multiple errors and I'm assuming it has something to do with python. I'm not entirely sure how the font object creation works but I use the mel command CreatePolygonType; to create the type and then a python command to edit the type of each type object. However, the process seems to be CreatePolygonType;>Creates Text Object>Errors occur while the program selects each text object again. I'm not sure what maya is doing when it goes over each text object but it seems the timing of this can conflict with my setting the text values and if maya is not freshly restarted it can interfere and cause text objects to be missing in the final graph. To give an idea here is some example code to spawn 10 text objects and set their numbers. Run the code once and it should spawn 10 text objects with different numbers. Delete all objects and run the script again and look at each object and there ought to be some text missing from one of them.
{
python "import maya.cmds as cmds";
int $num = 30;
for($x=0;$x<10;$x++){
CreatePolygonType;
$txtCmd = "python \"cmds.setAttr('type"+($x+1)+".textInput', u'"+$num+" "+$num+"', type='string')\"";
eval $txtCmd;
$num++;
}
}
I'm not sure if having the program wait would help but the command
pause -sec 10;
Only seems to pause maya entirely and the text errors happen and so does the missing text objects. The good news is the text doesn't seem to mess up when maya has been restarted, only after running the script multiple times.

Here you can see the number 120 is missing after running my chart code twice, the selection of 600 is from it going over each text object after they were created. I think that I'm changing the contents of the text objects before maya has finished doing its text creation process and so having the program wait until it is done, then change things like font size and text would work better. If anyone knows a way to do this or understands more about how the type tool works please let me know.
2) My other question is how to set the alignment of text. I set the font size using
setAttr "type1.fontSize" 10;
Except in my program I use an expression and it gets the font size from a locator control's attributes and allows for dynamic font changing via code.
string $fontCmd = "expression -s \"type"+($i+1)+".fontSize = locator_C.FontSize;\" -o typeMesh1 -n \"fontsize"+($i+1)+"\" -ae 1 -uc all ;";
eval $fontCmd;
I'd like to do the same to make each number right aligned but unfortunately unlike changing the font the alignment gives the same command every time in the script editor window:
import maya.app.type.AEtypeTemplate; maya.app.type.AEtypeTemplate.textAlignmentChange("type1")
It's python and it seems to make the text object center aligned but there's nothing I can change in the command except the name of the type object it is affecting, so unlike changing the font size I can't seem to specify left, center, or right align because its not an attribute of type. If anyone knows how to affect this process please let me know.
Thank you for taking the time to read my reply, again my questions are 1) How to set and edit text objects in a stable and predictable way so they don't get corrupted, and what that python error might be and 2) how to set text object alignment with code.
Thanks!