Houdini, Python, Scripting

ns_Startup


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 on my “Renderfarm”….2 Clients.

(See the deadline scripts enhancements down below).

To pass the right environments 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

from __future__ import print_function
import sys
import traceback

from CallDeadlineCommand import CallDeadlineCommand

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

# 
# 
# Code Before
# 
#

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

HIPFILE = hou.getenv("HIPFILE")
root = ET.Element("ENV")
environmentVariables = ET.SubElement(root, "EnvironmentVariables")
ET.SubElement(environmentVariables, "EnvironmentVariables",  variable="PATH", value=hou.getenv("PATH"))
ET.SubElement(environmentVariables, "EnvironmentVariables",  variable="HOUDINI_PATH", value=hou.getenv("HOUDINI_PATH"))
ET.SubElement(environmentVariables, "EnvironmentVariables",  variable="HOUDINI_OTLSCAN_PATH ", value=hou.getenv("HOUDINI_OTLSCAN_PATH"))
ET.SubElement(environmentVariables, "EnvironmentVariables",  variable="HOUDINI_TOOLBAR_PATH", value=hou.getenv("HOUDINI_TOOLBAR_PATH"))
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']))
        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 variables before the clients begin to render.

<YOUR_DeadlineRepository>\plugins\Houdini\Houdini.py

from System import *
from System.Diagnostics import *
from System.IO import *

from Deadline.Plugins import *
from Deadline.Scripting import *

import socket, traceback

import xml.etree.cElementTree as ET



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

        ##########################################
        #NS_MOD-START#############################
        
        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:
            self.LogInfo("ns_Version> cant set Environment Variables!")

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

 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