2
$\begingroup$

I have a text object and a scrip that takes an int value from custom property and applies to the text.

The script works in animation preview (User Perspective), but then it comes to rendering script isn't being called out to change value.

import bpy

scene = bpy.context.scene
TextObject = scene.objects['TimerText']
#function that formats string
def TimeCounter(scene):
    value = TextObject.data['time']
    min = int(round(value/60, 60))
    sec = value-(min*60)
    
    TextObject.data.body = 'Time ' + str(min) + ':' + str(sec).zfill(2)

bpy.app.handlers.frame_change_post.append(TimeCounter)

Frame 415 in render Frame 415 in user Perspective

$\endgroup$
1
-1
$\begingroup$

I looked at other results and I applied their examples to my code.

I added this variable in my TimeCounter function, that gets evaluated value from custom property. eval_text = TextObject.evaluated_get(depsgraph) and also changed def TimeCounter(scene): to def TimeCounter(scene, depsgraph): And in the end this script was here to recompile the results,

    bpy.app.handlers.frame_change_post.clear()
    bpy.app.handlers.frame_change_post.append(TimeCounter)
    
def unregister():
    bpy.app.handlers.frame_change_post.remove(TimeCounter)
    
if __name__ == "__main__":
    register() 

It also works without this long code.

bpy.app.handlers.frame_change_post.append(TimeCounter)

Here's full working code:

import bpy

scene = bpy.context.scene
TextObject = scene.objects['TimerText']

def TimeCounter(scene, depsgraph):
    eval_tex = TextObject.evaluated_get(depsgraph)
    value = eval_tex.data['time']
    min = int(round(value/60, 60))
    sec = value-(min*60)
    
    TextObject.data.body = 'Time ' + str(min) + ':' + str(sec).zfill(2)
def register():
    bpy.app.handlers.frame_change_post.clear()
    bpy.app.handlers.frame_change_post.append(TimeCounter)
    
def unregister():
    bpy.app.handlers.frame_change_post.remove(TimeCounter)
    
if __name__ == "__main__":
    register()
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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