Jump to content
Krion

Get time and date as a global variable

Recommended Posts

Hi,

 

I would like to avoid renders or exports from being overridden. I thought putting a time variable in the filename would be able to fix that for me.
 

I’ve found this _HIP_SAVETIME variable here, but that’s not enough as I can still make changes after I have saved the hip and export/override.

Does anyone have any ideas on how to accomplish this?

 

Thanks, :) 

Share this post


Link to post
Share on other sites

I think you can set this through a python expression with the datetime module.

import datetime

date = datetime.datetime.now()
export_date = date.day + "_" + date.month + "_" + date.year + "_" + date.hour + "_" + date.minute

filepath = hou.Node(".").Parm("my_export_path")
split = filepath.split("/")
new_filepath = split[0] + "/" + .... + export_date + split[-1]
hou.Node(".").setParm({"my_export_path" : new_filepath})

And you put this in a callback script of a custom button.

I'm not really into python and Houdini those times so I'm not sure if this would work, but give it a try ;)

 

Cheers,

Share this post


Link to post
Share on other sites

I second the use of the datetime module as well.

Here’s the documentation for that specific module.

I found myself in a similar spot when I changed naming conventions for saving project files. I was always doing the whole 01_, 02_ thing, until I realized it wasn’t very intuitive for me. So I created a custom Python shelf tool that saves my hip files to a specific location using a date based naming convention. Here’s a snippet of the code containing the date/time section:

def filePrep(self):
        timeStamp = datetime.datetime.now().strftime("%m-%d-%y_%I_%M_%p_") if self.ui.sys_time.isChecked() else None

The sys_time portion is Qt-centric code since I’m wrapping it all in a QWidget using PySide2, but after all is said and done, the script outputs a directory which is then fed to the hou.hipFile.save() method and saves it.

As an example, the code would spit out something like: $HOME/Projects/(Project Name Here)/hipfiles/02-18-20_10_49_AM_filename.hip

Those % characters are format codes you can feed to the strftime method to return a string according to what you need. Check out the linked documentation.

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×