0
$\begingroup$

I want to give an explanation in text during an animation I made in blender. However, with my current script, I only see the second text displayed during the whole animation. How do I change my code such that for frame 40-60 the first text is shown, and for frame 75-83 the second text?

Thanks in advance!

import bpy

scene = bpy.context.scene
obj = scene.objects['Text']


def recalculate_text(scene):
    frame = scene.frame_current

    for frame in range(40, 60):
        obj.data.body = 'First Text'
    
    for frame in range(75, 83):
        obj.data.body =  'Second Text' 
        
bpy.app.handlers.frame_change_pre.append(recalculate_text)
$\endgroup$
1
2
$\begingroup$

Get the object data (font curve), ask for the frame and check whether it's in a specific range using python's range(). Code based on Updating text object in Blender 2.81 using python

import bpy

scene = bpy.context.scene
obj = scene.objects['Font Object']
font_curve = obj.data

def recalculate_text(scene):
    
    if scene.frame_current in range(40, 60):
        font_curve.body = "First Text: " + str(scene.frame_current)
        
    if scene.frame_current in range(75, 83):
        font_curve.body = "Second Text: " + str(scene.frame_current)
    
    else:
        font_curve.body = "Current Frame: " + str(scene.frame_current)

def register():
    bpy.app.handlers.frame_change_post.append(recalculate_text)

def unregister():
    bpy.app.handlers.frame_change_post.remove(recalculate_text)

register()
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.