Jump to content

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


Hyrulean

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?

 

Link to comment
Share on other sites

  • 3 weeks later...

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
Link to comment
Share on other sites

  • 1 month later...

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
Link to comment
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
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...