Atom Posted December 13, 2016 Share Posted December 13, 2016 (edited) Hi All, I was playing around with exporting networks as python code. Here is a short script you can place in a Shelf Tool to export networks into executable python code. The resulting Python file appears on your desktop in a folder called HIPAsCode and is named like your .hip file. Certain parameters don't convert well. Fortunately those parameters are detectable and you can just comment those lines out. (i.e. hou_parm.set("{...) The fallout for commenting these troublesome lines of code are that the node in question will simply fallback default values instead of the values from the original .hip file. import hou, os # Framerange. frame_start = hou.playbar.playbackRange()[0] frame_end = hou.playbar.playbackRange()[1] # Construct paths. export_name = "%s.py" % hou.expandString("$HIPNAME") #"Scene1.py" home = os.path.dirname(os.path.expanduser("~")) desktop = os.path.normpath(os.path.join(home, 'Desktop')) project_dir = os.path.normpath(os.path.join(desktop, 'HIPAsCode')) file_output = os.path.normpath(os.path.join(project_dir, export_name)) # Create the project directory if it does not exist. if not os.path.exists(project_dir): os.mkdir(project_dir) file = open(file_output, "w") file.write("import hou\n\n") file.write('# Some node creation parameters do not work. bug H15.5?\n') file.write('# Before you execute this resulting code, use find/replace hou_parm.set("{ with #hou_parm.set("{\n') file.write('# This will comment the lines that do not currently work.\n\n') s = "hou.playbar.setPlaybackRange(%s,%s)\n" % (frame_start, frame_end) file.write(s) # Export nodes as code. lst_node_root = ["/obj","/shop","/out"] for node_path in lst_node_root: start_node = hou.node(node_path) s = start_node.asCode(brief=True, recurse=True, save_creation_commands=True, save_spare_parms=True) file.write(s) file.close() Edited December 13, 2016 by Atom 2 Quote Link to comment Share on other sites More sharing options...
tamagochy Posted October 5, 2022 Share Posted October 5, 2022 Hey, how load this file back to the houdini to restore information from file? 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.