def gplay(node, path): gplay = hou.getenv('HFS') + r"\\bin\gplay.exe" if not os.path.isfile(pathCheck): hou.ui.displayMessage('A geometry has not been written yet.', severity=hou.severityType.Warning, help="Current geometry path is: " + path, title="Gplay File Check") else: log.node(node, 1, "Opening: " + path) proc = subprocess.Popen([gplay, path], shell=True)
def remove(node, parm): path = os.path.normpath( node.evalParm(parm.replace('deleteHistory', 'historydir'))) if path != "": log.node(node, 1, "Removing: " + path) try: shutil.rmtree(path) except: print "Directory has been pre-cleared." node.parm(parm.replace('deleteHistory', 'historydir')).deleteAllKeyframes() node.parm(parm.replace('deleteHistory', 'historydir')).set('')
def post(node): nodePath = node.path() function = inspect.stack()[0][3] try: if node.evalParm("tpostrender"): script = node.evalParm("postrender") if script: if node.evalParm("lpostrender") == "python": exec(script) else: hou.hscript(script) except (KeyboardInterrupt, SystemExit): log.node(node, 1, "Interrupt requested of "+function+" for "+nodePath+"...exiting") return
def init(node): nodePath = node.path() function = inspect.stack()[0][3] try: hou.hscript('setenv ASSET = '+path.asset(node)) hou.hscript('setenv COMPONENT = '+path.component(node)) hou.hscript('setenv JOB = '+path.hq_project_path(node).replace('\\','/')) #hou.putenv("ASSET", path.asset(node)) #hou.putenv("COMPONENT", path.component(node)) #hou.putenv("JOB", path.hq_project_path(node)) except (KeyboardInterrupt, SystemExit): log.node(node, 1, "Interrupt requested of "+function+" for "+nodePath+"...exiting") return
def clear(node): nodePath = node.path() function = inspect.stack()[0][3] try: hl = node.evalParm("history_list") log.node(node, 1, "Clearing unlocked history") for i in range(1, hl + 1): hL = node.evalParm('historyLock' + str(i)) if hL != 1: node.parm('historydir' + str(i)).deleteAllKeyframes() node.parm('historydir' + str(i)).set('') except (KeyboardInterrupt, SystemExit): print "Interrupt requested of " + function + " for " + nodePath + "...exiting" return
def execute(kwargs): node = kwargs['node'] nodeName = node.path() function = inspect.stack()[0][3] try: que = node.evalParm("que") if que != 0: log.node(node, 1, "\nRendering Queue from: " + str(nodeName)) for i in range(1, que + 1): try: render(kwargs, i) except: return except (KeyboardInterrupt, SystemExit): log.node( node, 1, "Interrupt requested of " + function + " for " + nodeName + "...exiting") return
def path(node, path): path = os.path.dirname(os.path.abspath(path)) pl = platform.system() log.node(node, 2, "Your Platform is: " + str(pl)) log.node(node, 1, "File path to Browse: " + path) skp = 0 cmd = "explorer" if pl == "Windows": cmd = "explorer" elif pl == "Linux": cmd = "nautilus" elif pl == "Darwin": cmd = "open" else: skp = 1 hou.ui.displayMessage("Can't detect operating system to launch file browser.", severity=hou.severityType.ImportantMessage, default_choice=1, close_choice=1, help="Please PM me and tell me the ouptut from the python shell of: 'import platform, platform.system()' and your command line file browser for your operating system and I can add it.", title="Browse Path") if skp == 0 : if os.path.isdir(path) : proc = subprocess.Popen( [cmd, path]) else: hou.ui.displayMessage("This directory currently does not exist. " + path, severity=hou.severityType.ImportantMessage, default_choice=1, close_choice=1, help="This means your file has not yet been written to disk.", title="Browse Path")
def execute(node): dC = node.evalParm('enable_ondelete') if dC == 1: path_cache = path.hq_project_path(node) if os.path.isdir(path_cache): log.node( node, 0, "The cache directory proposed to be removed is: " + path_cache) if not hou.hscriptExpression('opisquitting()'): if hou.ui.displayMessage( "Do you want to PERMANENTLY delete the caches created by: " + node.path(), buttons= ("Yes, I do not need these caches for any scene file or asset.", "No, I'll clean my files up later."), severity=hou.severityType.ImportantMessage, default_choice=1, close_choice=1, help= "Inorder to help with project cleanup, this is a method for you to help delete dead file trees on disk, and as the author of this content you'll know best if you'll ever need these files again. " + path_cache, title="File Cache Cleanup") == 0: if hou.ui.displayMessage( "As a warning these files can not be undeleted.", buttons= ("Yes, I understand I am deleting my caches forever.", "Oops, I do not want my caches deleted."), severity=hou.severityType.Warning, default_choice=1, close_choice=1, help= "As one last heads up we want to double check that you do want to delete your file caches PERMANENTLY. This is a check encase you've created any asset or are referencing these files in another scene. " + path_cache, title="File Cache Cleanup") == 0: log.node(node, 0, path_cache) shutil.rmtree(path_cache)
def makedirs(node, list_dir): nodePath = node.path() function = inspect.stack()[0][3] try: log.node(node, 2, "Making Directories.") for path in list_dir : log.node(node, 2, path) if not os.path.exists(path): os.makedirs(path) except (KeyboardInterrupt, SystemExit): log.node(node, 1, "Interrupt requested of "+function+" for "+nodePath+"...exiting") return
def save(node, farm=None): nodePath = node.path() function = inspect.stack()[0][3] try: hiplocal = os.path.abspath(hou.hipFile.name()) hipfarm = path.hq_hip(node) log.node(node, 1, "Saving your local hip.") log.node(node, 2, hiplocal) hou.hipFile.save() log.node(node, 1, "Backing up your local hip.") hou.hipFile.saveAsBackup() if farm: log.node(node, 1, "Copying your hip to the farm.") log.node(node, 2, hipfarm) copyfile(hiplocal, hipfarm) except (KeyboardInterrupt, SystemExit): log.node( node, 1, "Interrupt requested of " + function + " for " + nodePath + "...exiting") return
def execute_farm(node, localnode=None): if not localnode: localnode = node nodePath = node.path() function = inspect.stack()[0][3] try: begTime = datetime.datetime.now() log.node(node, 2, "\n Begin Time of Total Export: " + str(begTime) + " \n") if hq.hq_hfs(node)[1]: if node.parent().parm("file_type"): ext = node.parent().evalParm("file_type") if ext == 'md' or ext == 'ip': log.node( node, 0, "Not rendering to farm as your image type is set to Mplay." ) return renderscripts.pre(node) log.node(node, 2, "Rendering Node : " + str(node.path())) init(node) list_dir = [] list_dir.append(path.hq_project_path(node)) if node.parm("hq_hip_action"): if node.evalParm("hq_hip_action") == "use_target_hip": list_dir.append(os.path.dirname(path.hq_hip(node))) elif node.evalParm("hq_hip_action") == "use_ifd": list_dir.append(os.path.dirname(path.hq_input_ifd(node))) if node.parm("hq_makeifds"): if node.evalParm("hq_makeifds"): list_dir.append(os.path.dirname(path.hq_outputifd(node))) if localnode: ntype = localnode.type() name = ntype.nameComponents()[2] if name == 'VFX_geometry': list_dir.append(os.path.dirname(path.sopoutput(node))) if name == 'VFX_dop': list_dir.append(os.path.dirname(path.dopoutput(node))) if name == 'VFX_comp': list_dir.append( os.path.dirname(path.copoutput(node, localnode))) if name == 'VFX_opengl': list_dir.append( os.path.dirname(path.picture(node, localnode))) if name == 'VFX_ifd': list_dir.append( os.path.dirname(path.vm_picture(node, localnode))) if localnode.parm("soho_outputmode"): if localnode.evalParm("soho_outputmode"): list_dir.append( os.path.dirname(path.soho_diskfile(node))) if localnode.parm("vm_inlinestorage"): if not localnode.evalParm("vm_inlinestorage"): list_dir.append( os.path.dirname( path.vm_tmpsharedstorage(node))) list_dir.append( os.path.dirname(path.vm_tmplocalstorage(node))) if localnode.parm("vm_deepresolver"): if localnode.evalParm("vm_deepresolver") == 'shadow': list_dir.append( os.path.dirname(path.vm_dsmfilename(node))) if localnode.evalParm("vm_deepresolver") == 'camera': list_dir.append( os.path.dirname(path.vm_dcmfilename(node))) #relying on soho_mkpath for Extra Image Planes to make the directories #vm_filename_plane(hq_node,node,parm) makedirs(node, list_dir) save(node, 'farm') #Print the environment at the time of processing env_path = str( path.hq_project_path(node) + '/houdini_environment.json') log.node(node, 2, "Houdini Environemt Log : \n" + env_path) log.env(node, env_path) if oppath.node_sim(node): log.node(node, 2, "Submitting Simulation") node.node("hq_sim/hq_sim").parm('execute').pressButton() else: log.node(node, 2, "Submitting Renders") node.node("hq_render").parm('execute').pressButton() renderscripts.post(node) else: hou.ui.displayMessage( "Not deployed to the farm due to version mismatch.", title="Version Mismatch") log.node(node, 2, "Done with all Processing! \n") #TimeCheck endTime = datetime.datetime.now() tolTime = endTime - begTime log.node(node, 2, "End Time of Total Export: " + str(endTime)) log.node(node, 2, "Total Time of Export: " + str(tolTime) + " \n") except (KeyboardInterrupt, SystemExit): log.node( node, 1, "Interrupt requested of " + function + " for " + nodePath + "...exiting") return
def execute_local(node, node_type): nodePath = node.path() function = inspect.stack()[0][3] try: begTime = datetime.datetime.now() log.node(node, 2, "\nBegin Time of Total Export: " + str(begTime) + " \n") renderscripts.pre(node) init(node) if node_type == 'first': log.node(node, 1, "Render first frame only.") execute_first(node) elif node_type == 'local': log.node(node, 1, "Render Local.") elif node_type == 'back': log.node(node, 1, "Render Local in Background.") list_dir = [] list_dir.append(os.path.dirname(path.file(node))) makedirs(node, list_dir) node.parm('loadfromdisk').deleteAllKeyframes() node.parm('loadfromdisk').set(1) node.parm('ver').deleteAllKeyframes() node.parm('ver').set(hou.getenv("HIPNAME", 'default-0001')) if node.evalParm("f1") != node.evalParm("f2"): node.parm('frame').deleteAllKeyframes() node.parm('frame').setExpression('$FF') save(node) file_type = node.evalParm("file_type") if file_type == '.abc': log.node(node, 1, "Caching ABC: " + str(nodePath)) node.node("AlembicCaching").parm('execute').pressButton() node.node("import_alembic").parm('reload').pressButton() if file_type == '.fbx': log.node(node, 1, "Caching FBX: " + str(nodePath)) fbx.exexcute(node) node.node("import_fbx").parm('reload').pressButton() if node_type == 'local' or node_type == 'first': log.node(node, 1, "Caching Local: " + str(nodePath)) node.node("ROPs/geometry").parm('execute_local').pressButton() node.node("read_back").parm('reload').pressButton() if node_type == 'back': log.node(node, 1, "Caching Local in Background: " + str(nodePath)) node.node("ROPs/geometry").parm('executebackground').pressButton() node.node("read_back").parm('reload').pressButton() if node.evalParm("mantra_archive") and file_type in '.bgeo': log.node(node, 1, "Caching Mantra Archive: " + str(nodePath)) node.node("ROPs/MantraArchive").parm('execute').pressButton() node.node("read_back").parm('reload').pressButton() if node.evalParm("history_auto"): history.update(node) if node.evalParm("enable_queue") and not node.evalParm("que"): queue.Execute(node) color.change(node) renderscripts.post(node) log.node(node, 1, "Done with all Processing! \n") #TimeCheck endTime = datetime.datetime.now() tolTime = endTime - begTime log.node(node, 2, "End Time of Total Export: " + str(endTime)) log.node(node, 2, "Total Time of Export: " + str(tolTime) + " \n") except (KeyboardInterrupt, SystemExit): log.node( node, 1, "Interrupt requested of " + function + " for " + nodePath + "...exiting") return
def render(kwargs, i): node = kwargs['node'] nodeName = node.path() function = inspect.stack()[0][3] try: que = node.evalParm("que") eC = node.evalParm("enableCommand") if node.evalParm("enableSaveHIP"): hou.hipFile.save() hou.hipFile.saveAsBackup() try: ropparm = node.node(node.evalParm('rop' + str(i))) except (AttributeError): log.node(node, 1, "Verify the render path for Queue item: " + str(i)) return if ropparm != None: roppath = ropparm.path() ropnode = hou.node(roppath) if eC == 1: try: ropcommand = node.evalParm('command') if ropcommand == 'custom': ropcommand = node.evalParm('custom') if ropcommand == 'rop' and node.evalParm('cmnrop0') != '': ropcommand = node.evalParm('cmncommand0') except (AttributeError): log.node( node, 1, 'No button type "' + str(ropcommand) + '" on node ' + str(ropparm.path())) return #else : # print "No Rop button specified to process." else: ropcommand = node.evalParm('command' + str(i)) ropenable = node.evalParm('enableQue' + str(i)) if ropenable == 1: log.node(node, 1, "Queue Item: " + str(i) + " of " + str(que)) log.node( node, 1, "Pressed Button: " + str(ropcommand) + " from node " + str(ropparm.path())) try: if ropnode.parm(str(ropcommand)) != None: ropnode.parm(str(ropcommand)).pressButton() else: node.hm().log.log( node, 1, "Verify the render path for Queue item: " + str(i)) except (KeyboardInterrupt, SystemExit): log.node( node, 1, "Interrupt requested of " + function + " for " + nodeName + "...exiting") except (AttributeError): log.node( node, 1, 'No button type "' + str(ropcommand) + '" on node ' + str(ropparm.path())) return else: log.node(node, 1, "Verify the render path for Queue item: " + str(i)) except (KeyboardInterrupt, SystemExit): log.node( node, 1, "Interrupt requested of " + function + " for " + nodeName + "...exiting") return
def update(node): nodePath = node.path() function = inspect.stack()[0][3] try: history_list = node.evalParm("history_list") history_cur = current(node) log.node(node, 2, "-- Updating Unlocked History --") log.node(node, 2, "Current History: " + history_cur) log.node(node, 2, "Number of History: " + str(history_list)) log.node(node, 2, "-------------------------") #check if it is zero then add one space if history_list == 0: node.parm('history_list').deleteAllKeyframes() node.parm('history_list').set(1) hl += 1 # Check if each line is full then add a new line hlcheck = 0 for i in range(hl, 0, -1): history_lock = node.evalParm('history_lock' + str(i)) history_dir = node.evalParm('history_dir' + str(i)) if history_lock == 0 and history_dir != "": hlcheck += 1 #print hlcheck if hlcheck == hl: node.parm('history_list').deleteAllKeyframes() node.parm('history_list').set(hl + 1) hl += 1 for i in range(1, hl + 1): history_lock = node.evalParm('historyLock' + str(i)) history_dir = node.evalParm('historydir' + str(i)) history_dirPrev = node.evalParm('historydir' + str(max(i - 1, 1))) log.node(node, 2, "History Number : " + str(i)) log.node(node, 2, "History Directory: " + str(history_dir)) if history_lock == 1: log.node(node, 2, "History is locked/n") continue elif history_lock == 0: log.node(node, 2, "History is not locked/n") if history_dir == "" and history_cur != history_dirPrev: #node.parm('history_list').deleteAllKeyframes() #node.parm('history_list').set(hl+1) node.parm('historydir' + str(i)).deleteAllKeyframes() node.parm('historydir' + str(i)).set(history_cur) log.node(node, 2, "Blank History & make sure it's not equal/n") break if history_dir == history_dirPrev: log.node(node, 2, "They are the same./n") continue if history_dir != "": log.node(node, 2, "Skip to next./n") continue if eVil >= 2: log.node(node, 2, "End Update") break except (KeyboardInterrupt, SystemExit): print "Interrupt requested of " + function + " for " + nodePath + "...exiting" return
def delete(node): nodePath = node.path() function = inspect.stack()[0][3] try: #https://docs.python.org/2/library/os.html -os.walk history_root = path.hq_project_path(node) history_list = node.evalParm("history_list") history_cur = current(node) log.node(node, 1, "Deleting unlocked history") history_saved = [] if os.path.isdir(history_root): history_saved.append(history_root) if os.path.isdir(history_cur): history_saved.append(history_cur) subpath = os.path.normpath(os.path.dirname(history_cur)) if os.path.isdir(subpath): history_saved.append(subpath) for i in range(1, history_list + 1): hL = node.evalParm('history_lock' + str(i)) history_dir = os.path.normpath( node.evalParm('history_dir' + str(i))) if node.evalParm('history_dir' + str(i)) != '': if os.path.isdir(history_dir): history_saved.append(history_dir) if os.path.isdir(os.path.dirname(history_dir)): history_saved.append(os.path.dirname(history_dir)) log.node(node, 2, "Saved History: ") log.node(node, 2, str(history_saved)) for dirpath, dirnames, filenames in os.walk(history_root, topdown=True, onerror=None): if os.path.normpath(dirpath) not in history_saved: try: shutil.rmtree(dirpath) log.node(node, 1, "Deleting: " + os.path.normpath(dirpath)) except: log.node(node, 1, "Skipping: " + os.path.normpath(dirpath)) else: log.node(node, 1, " Saved: " + os.path.normpath(dirpath)) log.node(node, 1, "Finished deleting unlocked history") except (KeyboardInterrupt, SystemExit): print "Interrupt requested of " + function + " for " + nodePath + "...exiting" return