Blender: real-time clock updating

In this short lesson, I shall tell you how to create a clock, updating in real-time. An example:

The clock works without animation keys.

You will need:

0. Blender (1 unit)

1. Animation Nodes add-on (1 unit)

2. Python knowledge (at least basic)

First of all, let's create a new scene. Place a couple of Text-class objects. Give a name «text_date» to one of them, «text_time» — to the second one.

Now we need a Python script to update time. Create the following text file:

from datetime import datetime
import bpy

def time_update(): # this function will update time
today = datetime.today()

if len(str(today.day)) == 2:
    dd = today.day
else:
   dd = '0'+str(today.day)

if len(str(today.month)) == 2:
   mm = today.month
else:
   mm = '0'+str(today.month)

yy = today.year

if len(str(today.hour)) == 2:
   h = today.hour
else:
   h = '0'+str(today.hour)

if len(str(today.minute)) == 2:
   m = today.minute
else:
   m = '0'+str(today.minute)

if len(str(today.second)) == 2:
   s = today.second
else:
   s = '0'+str(today.second)

bpy.data.scenes['Scene'].objects['text_date'].data.body = str(dd)+'.'+str(mm)+'.'+str(yy)
bpy.data.scenes['Scene'].objects['text_time'].data.body = str(h)+':'+str(m)+':'+str(s)

time_update() # launch time_update() function

Save file as date_and_time_updater.py. Make sure the file named exactly so, because windows can save it as date_and_time_updater.py.txt — at least if you are using the standard Notepad.

Split Blender interface into 3 parts: we need a standard 3D-viewport, a text editor and node editor.

In the Text Editor press Open and open our script. Enable the Register checkbox on the same panel to start the script automatically.

Now if you press Run Script — in the Text Objects the current date and time will appear. If you enabled the Register option, the current date and time will be automatically set every time, when you open this scene.

Let's make date and time updating in real-time now. You will need the Animation Nodes for it.

If the addon was installed properly, you will see a new tab in the Node Editor:

Select it, press New.

Add a Subprograms → Script node.

Select a Python file we created as a script. It's better to change the name («My Script») to something else.

Add the second node — Subprograms → Invoke Subprogram. Blender will offer to add the node, linked with our script:

The clock will start after it.

© Denis Skiba aka Mapper720

21.08.2018 (translated to English 16.04.2019)



Blender: real-time clock updating
Blender: real-time clock updating

In this short lesson, I shall tell you how to create a clock, updating in real-time. An example:

The clock works without animation keys.

You will need:

0. Blender (1 unit)

1. Animation Nodes add-on (1 unit)

2. Python knowledge (at least basic)

First of all, let's create a new scene. Place a couple of Text-class objects. Give a name «text_date» to one of them, «text_time» — to the second one.

Now we need a Python script to update time. Create the following text file:

from datetime import datetime
import bpy

def time_update(): # this function will update time
today = datetime.today()

if len(str(today.day)) == 2:
    dd = today.day
else:
   dd = '0'+str(today.day)

if len(str(today.month)) == 2:
   mm = today.month
else:
   mm = '0'+str(today.month)

yy = today.year

if len(str(today.hour)) == 2:
   h = today.hour
else:
   h = '0'+str(today.hour)

if len(str(today.minute)) == 2:
   m = today.minute
else:
   m = '0'+str(today.minute)

if len(str(today.second)) == 2:
   s = today.second
else:
   s = '0'+str(today.second)

bpy.data.scenes['Scene'].objects['text_date'].data.body = str(dd)+'.'+str(mm)+'.'+str(yy)
bpy.data.scenes['Scene'].objects['text_time'].data.body = str(h)+':'+str(m)+':'+str(s)

time_update() # launch time_update() function

Save file as date_and_time_updater.py. Make sure the file named exactly so, because windows can save it as date_and_time_updater.py.txt — at least if you are using the standard Notepad.

Split Blender interface into 3 parts: we need a standard 3D-viewport, a text editor and node editor.

In the Text Editor press Open and open our script. Enable the Register checkbox on the same panel to start the script automatically.

Now if you press Run Script — in the Text Objects the current date and time will appear. If you enabled the Register option, the current date and time will be automatically set every time, when you open this scene.

Let's make date and time updating in real-time now. You will need the Animation Nodes for it.

If the addon was installed properly, you will see a new tab in the Node Editor:

Select it, press New.

Add a Subprograms → Script node.

Select a Python file we created as a script. It's better to change the name («My Script») to something else.

Add the second node — Subprograms → Invoke Subprogram. Blender will offer to add the node, linked with our script:

The clock will start after it.

© Denis Skiba aka Mapper720

21.08.2018 (translated to English 16.04.2019)