Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Quick 'n' dirty script to include as part of a custom cache node, or a shelf tool to calculate cache times for frame sequences (Python 3)
import math
import os
import re
def timedelta(file1, file2):
t1 = os.path.getmtime(file1)
t2 = os.path.getmtime(file2)
time = abs(t2 - t1) / 60.0
min = math.floor(time)
sec = round((time - min) * 60.0)
return f"{min}m {sec}s"
def wedge_files(searchdir, prefix, wedgenum):
basename = f"{prefix}_{wedgenum}"
files = []
for file_ in os.listdir(searchdir):
if re.match(basename, file_):
files.append(os.path.join(searchdir, file_))
if len(files) < 2:
return files
def find_wedge_numbers(searchdir, prefix):
wedges = [re.match(rf"{prefix}(\d+)", x).group(1) for x in os.listdir(searchdir)]
wedges = list(set([x for x in wedges if x]))
return wedges
def report(cachedir, prefix):
report = ""
# Find all the different groups of files per match
for wnum in find_wedge_numbers(cachedir, prefix):
files = wedge_files(cachedir, "wedge", wnum)
if files:
report += f"Wedge {wnum}: {timedelta(files[0], files[-1])}\n"
return report
# r = report("C:/Users/James/Projects/dev/houdini/geo/cachedev/geo1/particles/001", "wedge")
# print(r)
Copy link

jamesrobinsonvfx commented Aug 20, 2021

Example usage in an hda's python module. Add the above script as a section called cachetime in your hda's Extra Files section

import toolutils

cachetime = toolutils.createModuleFromSection("cachetime", kwargs["type"], "cachetime")

def cachetime_comment(node):
    dir_ = os.path.dirname(node.evalParm("file_hard")) # Path to whatever sequence is being loaded by this filecache node
    if not dir_:
    comment =, "wedge")
    # node.setComment(comment)
    # node.setUserData("nodeinfo_Cache Times", comment)
    return comment

in a callback


on an error sop set to "message"


Copy link

jamesrobinsonvfx commented Aug 20, 2021

Inside of a node on an error sop
I suppose the sorting could use a bit of work!

Copy link

jamesrobinsonvfx commented Aug 20, 2021

Assuming a path convention of something like


where wedge_ is the {prefix}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment