2

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

Duarte Farrajota Ramos
  • 59,425
  • 39
  • 130
  • 187
Laimisl
  • 41
  • 1
  • 5

1 Answers1

-1

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()

Laimisl
  • 41
  • 1
  • 5