What is my goal: I want to make an animation of different products in the same studio environment, which shows the product during the course of the day. For that I am using the sun position in the world properties. In the top right corner I want a digital klok which uses the time from the sun position settings. For every product I want to use a new scene (product1, product2, etc), that way I can setup command line rendering and let my pc render every night.

How far did I got to reach my goal: First problem I got was the time in the top right corner. First I used animation nodes (as advised in this question Show time of day in render), but results were not consistent in command line rendering. Then I decided to use Leomoon plugin. This plugin has a problem with a little bug in Blender so it won't follow the animation when you parent the text to the camera. Because of that bug I have set-up another scene called "overlay". In the "overlay" scene I set the Leomoon plugin to dynamic and give it the expression bpy.data.scenes["Product1"].sun_pos_properties.time. The testing of the above scene product1 goes perfect. Problems come when I want to go the second product scene. At that moment the first product scene is not used, so the time does not change anymore.

Solutions I tried:

  • Make a sun position set up in the overlay scene. It doesn't work, time doesn't change, I expect this is because it is not the "active scene"
  • I searched a lot to change above expression to the active scene, but I can't find anything useful on that.

Solutions I don't want to use:

  • Create a new .blend file for every product and only use two scene's. This solution will use a lot of HD capacity because every blend will save all the studio data again.
  • Create a new overlay scene for every product. I will go with this one if there is no other solution, but that will be so many scenes and a lot of work to make all expressions and compositing use the correct scenes.

Is my goal possible and what would be the best way to reach it?


2 Answers 2


bpy.context.scene is the active scene. So you can use that with whatever Python solution that works for you as bpy.context.scene.sun_pos_properties.time.

You could also use app handler that gets the active scene anyway:

import bpy

def sun_position_time_handler(scene):
    time = scene.sun_pos_properties.time
    hour = int(time)
    minute = round(60*(time % 1)-0.5)
    text = str(hour).zfill(2) + ":" + str(minute).zfill(2)
    for o in scene.camera.children:
        if o.type=='FONT':
            o.data.body = text

This will change all text objects parented to the active camera to display time of the active scene on every frame change. You could use another app handler type.

In order to make it work from the command line you have to enable Text->Register for it in the Text editor. You have to have Auto Run Python Scripts enabled in the preferences:

enter image description here

Or you can save the script to a separate file like handler.py and run it from the command line:

blender -b C:\Test\test.blend -P C:\Test\handler.py -a

  • $\begingroup$ Thank you for your extensive answer. I only had to change my expression to get to my desired result. $\endgroup$
    – Zanzi
    Commented Dec 20, 2022 at 8:22
  • $\begingroup$ Glad it worked for you smoothly. $\endgroup$ Commented Dec 20, 2022 at 10:08
  • $\begingroup$ While using the expression in the Leomoon add-on I struggled that is why i Switched to your script. It works really smooth in the GUI when you change the time of day "by hand" just like you do in the gif in your answer. However, when I animate the time of day on my timeline, it doesn't work. It doesn't update the time and that way it is not possible to render it in the command line. Do you have any recommendation? $\endgroup$
    – Zanzi
    Commented Dec 20, 2022 at 11:06
  • 1
    $\begingroup$ @Zanzi. Sorry, I did not test it previously. You have to use frame_change_pre handler and you have to make sure the script is run when rendering so register it and enable auto run scripts, or run it while rendering from the command line. I updated the answer in order not to confuse people who stumble upon this in the future. Seems to work with simple test scene. $\endgroup$ Commented Dec 20, 2022 at 11:47

I'm not experienced with using Scenes, but if just having an object on the top right corner in a camera view is enough, I think you can do it with the Geometry Nodes setup below.

The setup has two main parts:

1. First we capture the Time information from the Sun Position panel and convert it into a string so we can create a text object via the String to Curves node. To capture the Time information, you can simply right click on its value box and choose Copy as New Driver. Now we go to the Value node at the very beginning of the setup, right click on its box and choose Paste Driver. It'll turn purple, indicating that it's being controlled by a driver, and it'll automatically update whenever Time changes.

Then, some maintenance: the Time value uses a generic float value, which means when time is $12:30$, for ex, it shows it as $12.5$. We isolate the hour part by using MathTruncate. We isolate the minutes part by using MathFraction, then map the 100-number float value to a 60-number hour value by MathMultiply'ing it by $60$. We finally join these two parts together by a Join Strings at the end, using "$:$" as the delimiter. There's also a Switch setup in between to make sure it always shows double digits by adding a $0$ at the start if the value has only one string.

2. Next part is making sure the generated clock text always faces the camera and stays fixed on the "screen" (camera view). Always-face-the-camera part is done by passing the camera's location and rotation information on to the text object's, via a Transform Geometry node. We use another one of those to move and scale the text relative to the screen—in reverse order for technical reasons.

enter image description here

Since the text is not an overlay but a real object, it can be obscured by other geometry when camera gets close to them. To fix that, you can enable the In Front option in Object Properties > Viewport Display:

enter image description here

  • $\begingroup$ Can you tell in which version of blender the example file is made? When i open it in Blender 3.0 i can't see the time. $\endgroup$
    – Zanzi
    Commented Dec 19, 2022 at 15:49
  • $\begingroup$ I'm using 3.5 Alpha. 3.0 is a bit too old but it should work for 3.3 onwards $\endgroup$
    – Kuboå
    Commented Dec 19, 2022 at 15:49
  • $\begingroup$ Thanks, I did check your file in 3.5 Alpha and this is a beautiful way of creating exactly what I want. I did however go with the solution of Martynas Žiemys because this was closer to what I already created and because it works in 3.0. $\endgroup$
    – Zanzi
    Commented Dec 20, 2022 at 8:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .