# making reusable text object

I want to simulate a multi-agent system with Blender. It's almost done, but I experience a problem.

System agents speak to each other by passing messages, and I want to pass messages between them. I considered a text object as container of these messages. There is no constraint on the number of agents.

I want to create one (or some) text object and reuse it many times, by only changing source and destination locations and body texts.

After some search, I realized, that there is no data_path that supports keyframe_insert() to change the body text. Beside that I found dynamic text, but my context is extremely different with that method's context.

I want to change text on every keyframe, and it depends on my simulation's input.

An application handler could be used to read subtitle data from your simulation module and display it by editing a text object.

import bpy
from bpy.app.handlers import persistent

@persistent
def frame_change(arg):
t = bpy.data.objects["Text"]
# here get the text you want to display
label = ("Frame # %d" % bpy.context.scene.frame_current)
t.data.body = label

bpy.app.handlers.frame_change_pre.append(frame_change)

• Thanks stacker for your attention. However it could be a solution; but It is not efficient at all. because i have so many message and this function should fill these message in all frames. but i need to change message only in key frames. – paradisal programmer Sep 12 '14 at 7:25
• please guide me if I am in wrong way – paradisal programmer Sep 12 '14 at 7:33
• When you don't need to change the text content in frames just skip the code until you reach a 'keyframe'. Compared to the costs of rendering I wouldn't worry on efficiency. – stacker Sep 12 '14 at 8:28