This script generates animation with a random number popping up on the screen periodically. In this specific case, frames go from 1 to 590. Numbers appear every 5 frames. At 25fps, this can generate 590/25=23.6 seconds of animation.
You can see an example here of this exact script in this video. This script’s specific section is from 6 second marker to approximately 25 second marker.
import bpy
import random
# text will appear every five frames, from frame 1 to 590, set up loop for that
# I rendered at 25fps, which means this would give you 590/25=23.6 seconds of appearing numbers
for counter in range(1,590,5):
# text object
text001_ops_object = bpy.ops.object
text001_ops_object.text_add()
# set characteristics of text object
text001_context_object = bpy.context.object
# each 5th frame will show one of the text choices below selected randomly
text_choice = random.choice(["1.99","2.99","3.99","4.99","5.99","6.99","7.99","8.99","9.99"])
text001_context_object.data.body = text_choice
# location of the text, this was based on my manually created scene
text001_context_object.location = [random.randint(-5,3),random.randint(-3,2),random.randint(1,3)]
# you can adjust the size/scaling of the text here with scaling for each of the x,y,z axes
text001_context_object.scale = 1,1,1
# set text object name, easier to manipulate later
text001_context_object.name = "name_9a"
# hide each text object initially at frame zero, important to set both hide and hide render
text001_context_object.hide = True
text001_context_object.hide_render = text001_context_object.hide
text001_context_object.keyframe_insert(data_path="hide", frame=0,index=-1)
text001_context_object.keyframe_insert(data_path="hide_render", frame=0,index=-1)
# now show the text object in appropriate frame (every fifth frame from the for loop)
appearing_frame = counter
text001_context_object.hide = False
text001_context_object.hide_render = text001_context_object.hide
text001_context_object.keyframe_insert(data_path="hide", frame=appearing_frame,index=-1)
text001_context_object.keyframe_insert(data_path="hide_render", frame=appearing_frame,index=-1)
# set random colors for the text that is being added
text001_data_materials = bpy.data.materials.new('visuals')
text001_data_materials.diffuse_color = (random.random(),random.random(),random.random())
text001_context_object.data.materials.append(text001_data_materials)
text001_context_object.active_material.keyframe_insert("diffuse_color",frame=appearing_frame)