# Clock with single hour hand to show current local time on running script?

It's a clock with only one single hour hand. 360 radians turns the selected handle the whole circle, but how to script it to read local time and calculate the degrees and assign it to the handle? I know there are quite a few steps to get there, but maybe some advice where to start?

import bpy
import os
import math

bpy.context.active_object.rotation_euler[2] = math.radians(0)


Q: Is it possible with bpy?

• Have you imported datetime module and either print the time string or look for hours minutes seconds properties? I often print the time to the console. import datetime print(datetime.datetime.now()) Dec 5, 2020 at 21:07
• How much experience do you have with Python or Blender Drivers? Dec 5, 2020 at 21:20
• To be honest, nearly none at all :/ I know syntax a bit at the moment, but however I am studying bpy intensely now. I want to find out the direction where to go next in automating the whole process. You helped me a lot. Thank you very much. Dec 5, 2020 at 21:29
• Robert please be honest. (Unless you would like to be President of the United States (of North America)) Please see driver info on noonoob. Hopefully a 5 minute video will be enough for today. Please see edited answer Dec 5, 2020 at 22:06
• Loosely related. blender.stackexchange.com/questions/38373/… Dec 5, 2020 at 22:13

## 1 Answer

Rotation by Driver

Some small sample to look at some of the numbers and a simple Driver

import datetime
import bpy
n = datetime.datetime.now()
print(n, n.hour, n.minute, n.second)
#allow this new rename of an existing function to be seen in Blender Drivers

bpy.app.driver_namespace["mytime"] = datetime.datetime.now

#in the driver called as mytime().hour (minute second)
#mytime().second * 2 * pi/60 the formula in the driver please improve
#your correct formula would use hours and minutes


In the text window we inform the driver namespace of a function that we can reference in the driver. This script needs to be run once. You can investigate further enhancements.

In the image you see a driver that refers to that same function. Please click on the image to see it larger. You can see the driver options by context clicking on the rotation value. Please improve the formula. The driver is on the rotation and is seen as the purple color. The driver window indicates this at the top. Please excuse my second rate registration. You see the formula which refers to the same function reference we created in the script. The function will only update when you move the frame position. The animation is to get you started with some discovery on your own. Perhaps you can show your improvements.

If you do not know the basics of using a driver then there are examples here at Blender Stack Exchange BSE and the website that has a name that rhymes with noonoob. What is written in this proposed answer is not a tutorial.

• Thank you very much. That's a good start! Dec 5, 2020 at 21:19