Hyrulean Posted March 31, 2022 Share Posted March 31, 2022 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? Quote Link to comment Share on other sites More sharing options...
Drughi Posted April 1, 2022 Share Posted April 1, 2022 You could use a python expression: file_name = hou.hipFile.basename() return file_name[-9:-6] Quote Link to comment Share on other sites More sharing options...
jordibares Posted April 16, 2022 Share Posted April 16, 2022 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 Quote Link to comment Share on other sites More sharing options...
PixelNinja Posted June 13, 2022 Share Posted June 13, 2022 (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, 2022 by PixelNinja 1 Quote Link to comment Share on other sites More sharing options...
Atom Posted June 16, 2022 Share Posted June 16, 2022 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.