I'm trying to update multiple text objects by testing it with changing the current frame (Please note this will be replaced with different field variables with decimal values in it) but instead of replacing the number it writes over it and creates several font objects.
How can I fix this so it replaces the previous value and doesn't create all those font objects?
import bpy
scene = bpy.context.scene
def recalculate_text(self):
font_curve = bpy.data.curves.new(type="FONT",name="Font Curve")
font_curve.body = 'Current Frame: ' + str(scene.frame_current)
font_obj = bpy.data.objects.update("Font Object", font_curve)
bpy.context.scene.collection.objects.link(font_obj)
font_curve2 = bpy.data.curves.new(type="FONT",name="Font Curve")
font_curve2.body = '2nd Field value: ' + str(scene.frame_current)
font_obj2 = bpy.data.objects.update("Font Object", font_curve2)
bpy.context.scene.collection.objects.link(font_obj2)
def register():
bpy.app.handlers.frame_change_post.append(recalculate_text)
def unregister():
bpy.app.handlers.frame_change_post.remove(recalculate_text)
register()
PS: I know I could do this with Animation nodes but I'm trying to get better at scripting.