August 20th 2020 07:00:03pm
In this tutorial I will teach you how to create a Houdini shelf tool that inserts a customized timestamp into your file output path. handy for those time when you are iterating render outputs and need easy distinction between versions based on date and/or time.
For those not wanting to build everything from scratch, I have made the shelf tool available for a small donation. You will find the link by clicking the button to the right.
Here’s just a brief gif showing the tool in action.
The best part is that you can easily change the date and time format to your liking. I usually like a date format that is year, month, day (20200821) which helps keep my files chronological when there are files spanning years. Otherwise you’ll get each month gathered together, but maybe that’s what you want. You could set the format to show 2020_08_21, or 08-21-20, or 21.08.2020, etc…
This will be the source code we are using in our shelf tool.
#setup timestamp
import time
from datetime import date
d = date.today()
#---------------------------------------------
# Complete format details: https://docs.python.org/3/library/datetime.html
#
# Date format:
# %y : Year without century
# %Y : Year with century
# %m : Month zero-padded
# %d : Day zero-padded
#
# Time format:
# %H : Hours 24hr clock
# %I : Hours 12hr clock
# %M : Minutes zero-padded
# %S : Seconds zero-padded
# -----------------------------------------------------------
#timestamp output
ts = "/" + d.strftime("%Y%m%d") + "_" + time.strftime("%H%M%S") + "_"
#---------------------------------------------
#since 3rd party developers can choose their own custom name for their parameters, there is
#a strong possibility that this script will need the list below updated for each new parameter
#not in the list. I have included Redshift and Mantra since I use these render engines and have
#access to the names that are used.
#For Octane, Arnold, Vray, etc... you will have to manually add them to the list or
#notify me of the parameter name so I can update this list.
#
types = ["RS_outputFileNamePrefix", "file","filename","vm_picture"]
#---------------------------------------------
#get selected node(s)
nodeSel = hou.selectedNodes()
selLen = len(nodeSel)
if(selLen == 1):
#determine which file parameter unique_name is being used
for t in types:
if(nodeSel[0].parm(t)):
fparm = nodeSel[0].parm(t)
break
fparm = None
if(fparm != None):
#get file parameter raw value
valRaw = fparm.rawValue()
#insert timestamp at last backslash
dice = valRaw.rsplit("/", 1)
r = ts.join(dice)
#set file parameter string
fparm.set(r, None, True)
else:
print "No file parameter found. Make sure you have only one (1) compatible node selected first."