# Handler-script updates in viewport but not in render

I'm completely stuck :-/

I've made a handler-script, that takes with every new frame a new line from the text-editor and puts that line into the text-object in 3d-space. It works absolutely fine - but when I want to render it, is it not working any more.

Why is that?? Other handler scripts from me are working fine...

import bpy

'''Text-Objekt muss angewählt sein und im Object-Mode
##################################################'''

def Text_Line_by_Line(Scene):

FrameNumber = bpy.context.scene.frame_current - 1 #aktuelle Frame-Nummer minus 1 weil python 1 = 0

TextFile = bpy.data.texts['Text'] #<------------Text-Name eingeben
TextLine = TextFile.lines[FrameNumber].body  # Nimmt die Text-Line als String

bpy.ops.object.editmode_toggle()
# Vorherigen Text löschen
bpy.ops.font.select_all() #selektieren
bpy.ops.font.delete()   #löschen

bpy.ops.font.text_insert(text=TextLine)  #Fügt den Text ein

bpy.ops.object.editmode_toggle()

bpy.app.handlers.frame_change_pre.clear()
bpy.app.handlers.frame_change_pre.append(Text_Line_by_Line)


Don't use operators in handlers

For the most part don't use operators in handlers. When rendering for example, the context needed will not be there. I imagine edit mode toggle means nada to the renderer. Use API methods and the passed argument scene

In example below, displays a line of bpy.data.texts["Text"] as the body of text object scene.objects["Text"]

import bpy

# pass arguments to build a handler
def text_body_handler(text):
# could also pass the name of text file and object... etc
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:
text_ob.data.body = text.lines[f-1].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"]))

• Wow.... Thank you sooo much! Your script is working perfect. Here I can see clearly, that I've got no idea about programming... I can't understand your script - but it works and I'm very happy :) I wish you a great time! – Andi Dec 16 '19 at 20:31
• Hi @Andi. In case the answer is "wow" or even solved your issue, please learn how to accept and upvote it for future visitors. Cheers – p2or Dec 17 '19 at 9:02