Writing the “PunchClock” add-on
Some tools can require the current date and time from the operating system clock. In Python, we can use the datetime
module to get them in our scripts, generally for versioning or logging purposes. There are no Blender properties designed specifically for time units, but an hour and a minute can be stored as two separate integer properties of an operator.
We know how to use the default
argument to declare the initial value of a property, but what if that value is not always the same? For example, the current hour and minute change during the day, but default
only sets static values.
But since invoke
is executed before all the other methods, we can set our default values programmatically in there.
To demonstrate that, we will create an add-on to create a time format text in the current scene. By default, the text displays the current time of the day, but the user can change that.
Creating the add-on script
Let’s create...