Deadline, Houdini, Python, Scripting

ns_Startup & Deadline Scripts


This python script was created to starting Houdini easily with the right workgroups/renderers etc.
Done with PyQt4. It has a WOL functionality for my NAS and a preset/job system.
I also modified my Thinkbox Deadline submission scripts to handle variable environments & the proper Houdini version on my “Renderfarm”….2 Clients.

(See the deadline scripts enhancements down below).

 

 

To pass the right environments/version through Deadline, i write out a .xml-file which is uniqe named against the render-.hip.

Common path:

C:\Users\<USER>\AppData\Local\Thinkbox\Deadline10\submitters\HoudiniSubmitter\DeadlineHoudiniClient.py

# 
# 
# Code Before
# 
#

############################################################################################
# NS_MOD-START #############################################################################

import xml.etree.cElementTree as ET
import hou
import os

HIPFILE = hou.getenv("HIPFILE")
root = ET.Element("ENV")
environmentVariables = ET.SubElement(root, "EnvironmentVariables")
hou_version = ET.SubElement(root, "HOU_Version")
ET.SubElement(environmentVariables, "EnvironmentVariables",  variable="PATH", value=hou.getenv("PATH").replace("\\", "/"))
ET.SubElement(environmentVariables, "EnvironmentVariables",  variable="HOUDINI_PATH", value=hou.getenv("HOUDINI_PATH").replace("\\", "/"))
ET.SubElement(environmentVariables, "EnvironmentVariables",  variable="HOUDINI_OTLSCAN_PATH ", value=hou.getenv("HOUDINI_OTLSCAN_PATH").replace("\\", "/"))
ET.SubElement(environmentVariables, "EnvironmentVariables",  variable="HOUDINI_SCRIPT_PATH ", value=hou.getenv("HOUDINI_SCRIPT_PATH").replace("\\", "/"))
ET.SubElement(hou_version , "HOU_Version",  variable="Version ", value=hou.getenv("_HIP_SAVEVERSION").replace("\\", "/"))
xml = ET.tostring(root)
HIPFILE = HIPFILE.split(".")

if os.path.exists(HIPFILE[0] + "_env.xml"):
    if hou.ui.displayMessage("Older Environment Variables .xml-file exist. Overwrite?" , buttons=("Yes", "Print to Console")) == 0:
        try:
            xmlFile = open(HIPFILE[0] + "_env.xml", "w")  
            xmlFile.write(xml)
            xmlFile.close()  
            print("\nns_Version> create " + HIPFILE[0]  + "_env.xml\n")
        except:
            pass
    else:
        print("\nns_Version> existing " + HIPFILE[0]  + "_env.xml:\n")
        try:           
            tree = ET.parse(HIPFILE[0] + "_env.xml")
            root = tree.getroot()
            for child in root:
                if child.tag == "EnvironmentVariables":
                    for i in child:
                        print(str(i.attrib['variable']) + " = " + str(i.attrib['value']))
                if child.tag == "HOU_Version":
                    print(str(i.attrib['variable']) + " = " + str(i.attrib['value']))
        except:
            print("ns_Version> something went wrong while parsing " + HIPFILE[0]  + "_env.xml!")
else:
    try:
        xmlFile = open(HIPFILE[0] + "_env.xml", "w")  
        xmlFile.write(xml)
        xmlFile.close()  
        print("\nns_Version> create " + HIPFILE[0]  +"_env.xml\n")
    except:
        pass

# NS_MOD-END #############################################################################
##########################################################################################

You get, in your hip folder, something like this:

This .xml-file, i read back when hython.exe starts and setting the right enviroment/version variables before the clients begin to render.

<YOUR_DeadlineRepository>\plugins\Houdini\Houdini.py

import xml.etree.cElementTree as ET

#
#
# Code Before
#
#
    def RenderExecutable( self ):

        version = self.GetPluginInfoEntryWithDefault( "Version", "16.0" ).replace( ".", "_" )
        build = self.GetPluginInfoEntryWithDefault( "Build", "none" ).lower()
        houdiniExeList = self.GetConfigEntry( "Houdini" + version + "_Hython_Executable" )


        ###################################################################################
        # NS_MOD-START # SETS THE RIGHT HOU-VERSION #######################################
        scene = self.GetPluginInfoEntryWithDefault( "SceneFile", self.GetDataFilename() )
        scene = RepositoryUtils.CheckPathMapping( scene )
        scene = scene.split(".")
        ns_version = ""
        try:           
            tree = ET.parse(scene[0] + "_env.xml")
            root = tree.getroot()
            for child in root:
                if child.tag == "HOU_Version":
                    for i in child:
                        ns_version = str(i.attrib['value'])
            houdiniExeList = houdiniExeList.replace("<ns_version>", "Houdini " + ns_version)
        except ValueError:
            self.LogInfo("ns_Version> cant set Houdini Version!")
        # NS_MOD-END #####################################################################
        ##################################################################################

#
#
# Code After
#
#



#
#
# Code Before
#
#
   
    def PreRenderTasks(self):

        ##################################################################################
        # NS_MOD-START # SETS THE RIGHT ENV VARIABLES ####################################
        
        scene = self.GetPluginInfoEntryWithDefault( "SceneFile", self.GetDataFilename() )
        scene = RepositoryUtils.CheckPathMapping( scene )
        scene = scene.split(".")
        try:           
            tree = ET.parse(scene[0] + "_env.xml")
            root = tree.getroot()
            for child in root:
                if child.tag == "EnvironmentVariables":
                    for i in child:
                        self.SetProcessEnvironmentVariable(str(i.attrib['variable']), str(i.attrib['value']))
                        self.LogInfo("ns_Version> set " + str(i.attrib['variable']) + " = " + str(i.attrib['value']))
        except ValueError:
            self.LogInfo("ns_Version> cant set Environment Variables!")

        # NS_MOD-END #####################################################################
        ##################################################################################
            
#
#
# Code After
#
#
           

In the Deadline “Configure Plugins…” Editor, i replaced the executable pathes with my <ns_version> tags.

 

 Hint:

Set HOUDINI_NO_ENV_FILE=1 to ignore user specific configurations.
More variables and descriptions find here: http://www.sidefx.com/docs/houdini/ref/env.html.

Another Hint:

Found this yesterday. Pretty good article about Houdini Environment Variables from Juraj Tomori:
Houdini tip | Taking advantage of environment variables