younglegend Posted November 25, 2017 Share Posted November 25, 2017 (edited) Hello! I came across this super useful script by F1 few weeks ago which allows me to save hip files with comments. But i'd like to know if there's a way to save a scene while staying in current session. (i.e a new file save but stay on the current hip file) import os.path as op import hou # Fetch tuple with index of pressed button and input text. choice, text = hou.ui.readInput('Type comments message', help='Type comments description.', title='Commented HIP', buttons=('OK', 'Cancel'), default_choice=1, close_choice=1) # If OK was pressed with some non-empty text. if choice == 0: path = hou.hipFile.path() # Replace existing comment. if text: dir, name = op.split(path) name = op.splitext(name)[0] name = name.rsplit('.', 1)[0] name = '%s.%s.hip' % (name, text) path = op.join(dir, name) path = op.normpath(path) hou.hipFile.save(path) print(path) Edited November 25, 2017 by kishenpj Quote Link to comment Share on other sites More sharing options...
garf Posted November 27, 2017 Share Posted November 27, 2017 I guess you would want to save the current session as temp file before running this script. Then once this script has run open the temp file. Quote Link to comment Share on other sites More sharing options...
garf Posted November 27, 2017 Share Posted November 27, 2017 (edited) import os.path as op import hou activeSession = hou.hipFile.name() print activeSession # Fetch tuple with index of pressed button and input text. choice, text = hou.ui.readInput('Type comments message', help='Type comments description.', title='Commented HIP', buttons=('OK', 'Cancel'), default_choice=1, close_choice=1) # If OK was pressed with some non-empty text. if choice == 0: # save tmp file tmp = ('').join(hou.hipFile.name().split('.')[0]) + '_tmp.hip' hou.hipFile.save(tmp) # set path name to the current session name path = activeFilename # Replace existing comment. if text: dir, name = op.split(path) name = op.splitext(name)[0] name = name.rsplit('.', 1)[0] name = '%s.%s.hip' % (name, text) path = op.join(dir, name) path = op.normpath(path) # save off the newly commented version hou.hipFile.save(path) # load the tmp file hou.hipFile.load(tmp) # rename it to the original session name hou.hipFile.setName(activeSession) print(path) It's clunky - but it does what you want it to Edited November 27, 2017 by garf 1 Quote Link to comment Share on other sites More sharing options...
younglegend Posted November 27, 2017 Author Share Posted November 27, 2017 3 hours ago, garf said: import os.path as op import hou activeSession = hou.hipFile.name() print activeSession # Fetch tuple with index of pressed button and input text. choice, text = hou.ui.readInput('Type comments message', help='Type comments description.', title='Commented HIP', buttons=('OK', 'Cancel'), default_choice=1, close_choice=1) # If OK was pressed with some non-empty text. if choice == 0: # save tmp file tmp = ('').join(hou.hipFile.name().split('.')[0]) + '_tmp.hip' hou.hipFile.save(tmp) # set path name to the current session name path = activeFilename # Replace existing comment. if text: dir, name = op.split(path) name = op.splitext(name)[0] name = name.rsplit('.', 1)[0] name = '%s.%s.hip' % (name, text) path = op.join(dir, name) path = op.normpath(path) # save off the newly commented version hou.hipFile.save(path) # load the tmp file hou.hipFile.load(tmp) # rename it to the original session name hou.hipFile.setName(activeSession) print(path) It's clunky - but it does what you want it to Might be a problem if the file size is big but this is a good workaround! ....and the only choice i guess. Quote Link to comment Share on other sites More sharing options...
younglegend Posted November 30, 2017 Author Share Posted November 30, 2017 Well, this one works! import os.path as op import hou activeSession = hou.hipFile.name() # Fetch tuple with index of pressed button and input text. choice, text = hou.ui.readInput('Type comments message', help='Type comments description.', title='Commented HIP', buttons=('OK', 'Cancel'), default_choice=1, close_choice=1) # If OK was pressed with some non-empty text. if choice == 0 and text: path = hou.hipFile.path() dir, name = op.split(path) # Discard extension. name = op.splitext(name)[0] # Discard one '.anytext' occurence at the end. name = name.rsplit('.', 1)[0] # Make new name with input text. new_name = '%s.%s.hip' % (name, text) # Finally, create an absolute path to save file to. new = op.normpath(op.join(dir, new_name)) # Save the file. hou.hipFile.save(file_name=new, save_to_recent_files=False) hou.hipFile.setName(path) print "File saved to - " + (new) 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.