HScript
From Odwiki
HScript is Houdini's general purpose scripting language. Be careful not to confuse the HScript language with hscript, Houdini's non-gui (batch) application.
Hscript is very similar to C-Shell in its syntax and structure. Houdini's Expression language is also used heavily when using HScript, it is rare you would write a script that contains only HScript commands and no Expressions. As a result, when learning HScript, don't focus solely on HScript itself, but always look at Expressions too.
For some common topics and fragments of code, please look in the HscriptCookbook and the HscriptFAQ.
Help
The most important commands are:
help which gives you a list of all HScript commands and exhelp which gives you a list of all Expressions.
The -k flag to the above commands will show you only the commands containing the word you are looking for. For example, to find all the HScript commands whose help contains the word "bundle" type:
help -k bundle
To find all the Expressions whose help contains the word "bundle" type: exhelp -k bundle
- Practice! Open up the Textport from Windows->Textport and play around with the two Help commands.
Houdini's Internal Structure
Houdini has a very simple and elegant internal structure; it is very similar to a Unix (or DOS) filesystem. Each of the Houdini editors is a directory (or "folder" in Windows-speak) and the various nodes are like "files" inside.
You navigate in the Textport using commands similar to unix. For example, to see the contents of a directory, type:
opls
To change into a directory, type:
opcf
Note that the above two commands are usually aliased (given an additional name) to their Unix counterparts, so in a default Houdini you can actually type ls and cd to do the same things. However, always be aware that the "real" HScript commands for moving around in the textport always start with op.
- Practice! In the Textport, go to the "root" of Houdini by typing:
- opcf /
- See what the different Editors' names are by typing:
- opls
Note to Houdini Select, Escape and Halo users: Even though you don't have direct interface access to some of the editors, you will still see their directories listed in the Textport. However, you cannot add new operators or make changes to existing operators inside these directories.
- Change into the obj directory by typing:
- opcf obj
- See the operators in Objects by typing:
- opls
This should show you a list of the default objects in the Object editor, or whatever Objects you have in your current Houdini session.
Learning HScript
Learning HScript is really easy, as the important actions in Houdini can be output to the textport, to help you learn. This does not happen automatically, but is done with the opscript command.
- Practice! In the Textport, navigate to the /obj directory.
- To see the commands used to re-create the object light1, just type:
- opscript light1
This will output a large amount of data, a lot of which isn't that important right now. However, if you typed in (or copy/pasted) all this text back into the Textport, it would create a light exactly like light1 except with a different name.
- To see a much shorter list of only the "essential" commands to recreate this Object, type:
- opscript -b light1
This will output a much smaller list of commands and data. The -b flag to opscript indicates "brief" output, so that any value that is just at default will not be output.
Use the help command to explore this further. Each line starts with an HScript command, so opcf /obj changes directory into the Object editor, the opadd command actually adds the new operator, the opparm command configures the parameters, opset sets the flag(s) on the operator etc.
Any line that starts with a hash (number sign) # symbol is a comment and is not executed by HScript.
These two lines:
\set noalias = 1
set saved_path = `execute("oppwf")`
are used to "remember" where the Textport's currect directory was, so at the end of the script, this line:
opcf $saved_path
will change back to the directory you started from. This isn't essential but is considered "polite" scripting, so your script doesn't leave someone else's textport where they don't expect it.
This is actually an example of using a Houdini Expression execute("oppwf") within an HScript script.
Have fun!!



