Hyrulean 1 Posted March 31 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
Drughi 34 Posted April 1 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
jordibares 97 Posted April 16 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. 1 Share this post Link to post Share on other sites
PixelNinja 76 Posted June 13 (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 June 13 by PixelNinja 1 Share this post Link to post Share on other sites
Atom 1,468 Posted June 16 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) 1 Share this post Link to post Share on other sites