I have about 300 text objects, of which the texts need to change during the animation (numbers in a graph). I came across this Python method using applicatoin handlers: Keyframe on text body in Python?
My problem is: it works if I do this for one object at a time, but not when i use a for loop:
for p in pricelist:
pname = p[0]
plist = p[1:]
text = bpy.data.objects[pname]
print(pname, text.data.body)
def update(self):
text = bpy.data.objects[pname]
frame = bpy.context.scene.frame_current
text.data.body = f'{plist[scene.frame_current]}'
def register():
bpy.app.handlers.frame_change_post.append(update)
def unregister():
bpy.app.handlers.frame_change_post.remove(update)
register()
(with pricelist being a list of lists, every row contains the object name (first item) and after that, for every frame a value in a string).
When I run it, nothing happens. Sometimes, I have not figured out when this occurs, I get the error "ReferenceError: StructRNA of type Object has been removed" in the terminal over and over again as the animation plays.
Why does this not work, and how do I get the texts of 300 objects to change in the animation in one go?
Thanks in advance for your thoughts!
text.data.body = f'{plist[scene.frame_current]}'
fortext.data.body = f'{plist[bpy.context.scene.frame_current]}'
, thescene
variable seems to be initialized before the script and might be invaliated at the time of execution of the callback $\endgroup$f'{plist[bpy.context.scene.frame_current]}
didn't yield any results $\endgroup$