How do I change the text in a Text Shape dynamically?
Normally, the text of a Text shape is not animatable. The resulting mesh will be evaluated once at the beginning
of the rendering and will not change as it is considered static (not changing over
time). A workaround is to assign a script controller to a property of the text shape
which will do two things: tell the renderer that the text shape is animated and thus
requires reevaluation on each frame, and set the actual text in the text property.
WARNING!
|
Changing the text object's text property in anything other than a controller applied
to the text object can lead to a renderer crash!
|
EXAMPLE
|
--Create a box and a text shape
b=box name: "ControlBox" wirecolor:blue
t=text name: "ControlledText" wirecolor:red
t.baseobject.renderable=true --set the shape to renderable
theCtrl = float_script() --create a float script controller
theCtrl.addNode "TheText" t --add a variable, connect to theText node
theCtrl.addNode "TheBox" b --add a variable, connect to the Box node
--Set the expression to assign the height of the box as string to the
--.text property of the text shape, then return 0 on the next line:
theCtrl.SetExpression "TheText.text = TheBox.height as string\n0"
t.kerning.controller=theCtrl --assign the controller to the kerning
animate on at time 100 b.height*=2 --animate the height of the box
max tool zoomextents all --zoom into the two objects
playAnimation() --play back the animation
--You should be able to render the scene without any problems
--and the text will show the height of the box in generic units.
|