SendingHscriptToHoudini

From Odwiki

Jump to: navigation, search

Scripting : Sending hscript data to Houdini via Python

The most straight-forward method of injecting hscript into Houdini from an external script is to source the material after it has been written to an intermediate file. This can be done manually from the Textport within the Interface, but the process can also be automated from the external script itself.

hcommand is an external program included in Houdini's bin directory that allows the user the ability to send information to the interface from a normal shell(bash, csh, windows cmd, etc). The only requirement is that a port has to be opened from the textport in the interface.

openport portNumber

At this point, Houdini is listening on the supplied port number for any external connections coming from hcommand. If the user were to simply enter a shell and type hcommand portNumber, an interactive connection to the interface listening on the open port would be established. The user would have the ability to type hscript commands into the shell, which the interface would interpret. As an alternative, the user also has the ability to send the hscript command along with the initial hcommand call in the shell.

hcommand portNumber hscript

This is useful to the python script for obvious reasons. With this ability, the script could use a system call to execute hcommand along with the port number chosen and a single line of hscript that tells Houdini to source an intermediate file.

#import needed modules
#composite the user-given elements into one cmd call
import os
portNumber = '2222'
sourceFile = 'c:/hscript.txt'
cmdCall = 'hcommand ' + portNumber + ' source ' + sourceFile
os.system(cmdCall)

After the system call returns its success/failure boolean, the shell will be automatically closed, effectively severing the connection with Houdini. To keep things clean, it's a good idea to make certain that the last line of the intermediate hscript file closes the open port to the interface.

closeport portNumber

Python scripting is an excellent way to automate repetitive tasks. hcommand is merely one way of getting that data into the interface. For a more detailed example, see PythonToHoudini.

Note for Windows

On Windows, you can't use telnet to an openport if you're using standalone mode which basically tells Houdini to operate as if the computer had no network ability. To turn it off, run the License Administrator. Then in the menu, choose File > Change License Server. Turn off Standalone mode. Hit Ok.

© 2009 od[force].net | advertise