Jump to content
Hyrulean

Making an expression to auto-version up caches to match the hip file version

Recommended Posts

Hello everyone.

 

I have looked this up a lot online but I can't find a way to solve it.

 

I am looking for a way to get the last 4 digits of a file so I can make my caches auto version up, acording to my hipfile name.

 

So basically if I have a hip file called "shotname_fx_v001.hip", then the last 4 digits I would call it in and make that be my version. I would also need to do a toggle to make that only be active when I need it. 

 

Any ideas on how I could approach that?

 

Share this post


Link to post
Share on other sites

You could use a python expression:

file_name = hou.hipFile.basename()
return file_name[-9:-6]

Share this post


Link to post
Share on other sites

A suggestion, don't use hard-coded numbers, eventually will break... perhaps something like;

file_name = hou.hipFile.basename()
return file_name.split("_")[-1]

In this way, as long as you keep using the same template separated by underscores, it will work, independently of the length of the string or even the amount of underscores.

  • Like 1

Share this post


Link to post
Share on other sites
Posted (edited)

For anyone working with versioning or extracting and data from filepaths I would recommend looking into regular expressions.

import re
file_name = hou.hipFile.basename()
match = re.search('v(\d+)')
return match.group(1)

 

This looks for any string matching a "v" followed by numbers and returns the numbers.

eg. "shotname_fx_v001.hip" -> "001"

It's is very powerful once you get the hang of it and essential for pipelining tasks.

Edited by PixelNinja
  • Like 1

Share this post


Link to post
Share on other sites

And one I use all the time.

def returnValidHoudiniNodeName(passedItem):
    # Thanks to Graham on OdForce for this function!
    # Replace any illegal characters for node names here.
    return re.sub("[^0-9a-zA-Z\.]+", "_", passedItem)

 

  • Like 1

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

×