1
$\begingroup$

I would like to move an object based on time in blender. The issue is, I would like to have it's translate values updated every time I open the scene (or while the scene is open), I don't want it to be based on a single continuous blender session.

So for example if I have a cube, it's gonna be on x location on January 1st, if I open the Blender file again on Jan 11th I'd need it's translate to be on x+10.

Have any of you had experience with python datetime inside Blender? The threads I found were from ages ago and I didn't manage to get anything useful out of them.

Thanks,

Dan

$\endgroup$

1 Answer 1

1
$\begingroup$

Just in case someone is looking for something similar - After some digging I worked out what I need

import bpy
from datetime import datetime
then = datetime(2020, 1, 1, 0, 0, 0)        # Random date in the past
now  = datetime.now()                         # Now
duration = now - then                         # For build-in functions
duration_in_s = duration.total_seconds()
hours = divmod(duration_in_s, 3600)[0]
minutes = divmod(duration_in_s, 60)[0]   
days  = divmod(duration_in_s, 86400)[0]

cube = bpy.data.objects["Cube"]
cube.location.x = minutes

Still not sure how to make it update automatically but this is good enough for my needs.

$\endgroup$

You must log in to answer this question.

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