Return a callable
Please read the handler docs https://docs.blender.org/api/current/bpy.app.handlers.html A handler method takes two arguments the scene
and the depsgraph
. You append a function to handlers. In above update
is a callable function whereas update(foo)
is the result of calling that function, which without a return, returns None
by default. Explaining error message.
That covered, using a method similar to answer here
Handler-script updates in viewport but not in render
Recommend passing the name rather than the object , otherwise object removal may cause null reference issues. The object is fetched from the scene objects collection by name in the handler.
Q code
import bpy
def update_text(name, old_text, new_text, key_frame):
def handler(scene, depsgraph):
text_ob = scene.objects.get(name)
if not text_ob:
return
f = scene.frame_current
text_ob.data.body = new_text if f >= key_frame else old_text
return handler
def register(update):
bpy.app.handlers.frame_change_post.append(update)
# while testing to avoid buildup
bpy.app.handlers.frame_change_post.clear()
# update text content
register(update_text("Text", "old", "new", 10))
Am currently using 2.90alpha and this is updating both in viewport and when rendered. Will find some issues with earlier versions of 2.8 not updating in render.
Check out the answer in link above re using a text data block as input using line numbers as frames. Instead of replacing body on each line could append or hold forward if a line is empty. (eg for example "old" on line 1, and "new" on line 10.

import bpy
# pass arguments to build a handler
def text_body_handler(text):
lines = len(text.lines)
# the handler method
def text_body(scene):
f = scene.frame_current
text_ob = scene.objects.get("Text")
if text_ob and f <= lines:
body = text.lines[f-1].body
if body:
text_ob.data.body = body
return text_body
bpy.app.handlers.frame_change_post.clear()
bpy.app.handlers.frame_change_post.append(text_body_handler(bpy.data.texts["Text"]))
Related
Updating text object in Blender 2.81 using python
Note also: Avoid mixing context with handlers. It may be the case that the scene being "handled" is not the context scene. (bpy.context.scene
) perhaps given a bit of a bum steer by answer in Q link..