Python

About

← Back

Content Creation

Create & Format Node

This function outlines the process for adding a geo node to the object network and formatting some of its display settings. The same process can be applied to nodes in other networks and can be a utility for the 123.py and 456.py startup files to automate its creation upon loading Houdini.

Reference: https://www.sidefx.com/docs/houdini/network/organize.html#bulk-changes

Set Node Shape

Using the available options noted in the list Node Shapes, the following snippet can be used to set a node's shape.

Add Custom Metadata To Node

The prefix of "nodeinfo_" is recognized by Houdini and allows for the custom metadata to be viewed in node info, as shown to the right.

image

Specify Node Creator

Create Network Boxes with Names

Network Box Comment

Network boxes have a field at the top of each where a string can be input to serve as a title; this is noted as the network box's 'Comment'. Multiple network boxes can have the same 'Comment' without issue.

Network Box Name

However, at the same time, each network box has a unique identifier as noted by its 'Name'. With Python, the createNetworkBox() method includes an argument to specify the unique name for each network box.

The value applied to this 'Name' is not visible from the network view, but can be called with Python using the following:

which then returns the following:

NetBox_0
NetBox

Get/Set Default Sticky Note & Network Box Colors

Get and set default colors for Houdini sticky notes, text, and network boxes. Default Houdini color codes are outlined in the following list: Default Node Colors.

References:

Group Name Via Operator Label

The Group SOP can use this script to set the group name to the name of the node, which mitigates the need to set the group name parameter within the SOP and the SOP name itself. Ultimately, this aligns the name of the node with the group name and can help with keeping group names organized.

Add Custom Parameters To Nodes

This script is intended to add custom parameters and folder organization to nodes for relaying parametric data to other nodes in the network, such as a control panel for an HDA.

Resources

Add Custom Parameter Values To Nodes

Method for setting parameter values with specified data type or expressions.

Menu Parameters

Clarification of the available operations that can be applied to a menu parameter.

Node Data

Numeric Digits From Node Names

HDA Module

Python Module code requires the HDA naming to be specified as PythonModule.

Reference: https://www.sidefx.com/docs/houdini/hom/hou/HDAModule.html

Queries

Search Nodes By Name & Composite Query

Using the nodesearch module, queries can be composed with matcher objects that isolate specific criteria, but can then be used individually or as part of a composite matcher group. In this example, the 2 geo and 1 material network nodes all have the string "sphere" in their names. The following matchers isolate by name and type, but are then combined.

image

The script above returns the following output based on the type of matcher.

Query By Name

(<hou.ObjNode of type geo at /obj/sphere0>, <hou.ObjNode of type geo at /obj/sph
ere1>, <hou.ShopNode of type matnet at /obj/sphere2>)

Composite Query: By Name & Type

[<hou.ObjNode of type geo at /obj/sphere0>, <hou.ObjNode of type geo at /obj/sph
ere1>]

Attribute Management

Rename Primitive Attribute Values

Python snippet for use in Houdini to rename a primitive attribute string value.

Callbacks

Callbacks are triggered by user-specified parameter value changes or via the parm.pressButton() function. For instance, the following links the color parameter select with the node color using a Python script callback.

image

Event Handlers

In the case of an HDA created inside of a GEO node, the following function is created within the Python Module event handler:

Meanwhile, the following call to the function above is made in the On Created event handler within the same HDA:

The output notes how each of the event handlers recognizes the corresponding node when the function is called from the On Created event. It reflects the HDA as the node while the Python Module recognizes the parent node, geo, as the node.

Node from OnCreated: hda
Node from Python Module: geo

Keyword Arguments

kwargs global dictionary variable.

Utilizing kwargs to get node and parameter information can be coordinated with the node's Python Module and individual callback scripts for each parameter.

image

Output when the string parameter is triggered:

Node Name: hda
Parameter: <hou.Parm string_parm in /obj/geo1/hda>
Parameter Name: string_parm
Parameter Value: ['custom string']

Output when the integer vector parameter is triggered:

Node Name: hda
Parameter: <hou.Parm int_vector_parmx in /obj/geo1/hda>
Parameter Name: int_vector_parm
Parameter Value: ['0', '1', '2']

Output when each of the multiparm instances are triggered:

Parameter Name: float_vector_parm1
Parameter Index: 1
Parameter Name: float_vector_parm2
Parameter Index: 2
Parameter Name: float_vector_parm3
Parameter Index: 3

Reference: https://www.sidefx.com/docs/houdini16.0/hom/tool_script#arguments

User Interface

Dialog Message Boxes

Using the hou.ui module, the following are some opportunities to provide user feedback in the form of a dialog box with interactive buttons.

Message

image

Confirmation

image

Custom Confirmation

image

The Details Label toggle displays the section with additional details, as specified in the argument.

image

Python Script In Node

Add a string parameter to the selected node and enable the following options:

  • Enable Multi-Line String.
  • Specify Language as Python.
  • Set Callback Script to the following, which navigates to the user-defined content within the Python panel and executes it whenever the content is changed.
  • An alternative is to add a button to the node and have the above snippet input into its Callback Script field. This will allow the user to click the button to specify when to run the code input into the node's new Python panel rather than automatically whenever it is changed.

The following collects all of the above and collects them into a script to add the Python panel to selected nodes.

Workspace Settings

123.py & 456.py Startup Scripts

Upon starting up Houdini, the 123.py startup script file is configured in Python to automate the creation of several nodes and specific settings in the obj, mat, and out networks. This includes the configuration of relevant parameter settings, all with the intent of being able to quickly start a project file consistently and with a basic project management structure.

My own custom123.py and 456.py startup scripts as well as collection of custom scripts are currently kept updated in the following GitHub repository and are available for anyone's use and own customization.

Edit Network Editor UI Preferences

Edit UI preferences for a Network Editor pane in a Houdini desktop/session via Python. Available preferences are noted in the following list Editor Preferences.

Playbar Configuration

This enables the realtime playback toggle on Houdini playbar. It can be integrated within the startup script to have it enabled when Houdini is opened.

Resources

Process Automation

These images capture some of the aspects that the workspace automation script addresses, namely the creation, formatting, and placement of nodes in the applicable networks: obj (Fig. 1), mat (Fig. 2), and out (Fig. 3). Other setup operations include configuring light and camera placements in the scene, material setups within each of the RS Material Builder nodes, and Redshift ROP node settings.

Fig. 1 Object Network
Fig. 1 Object Network
Fig. 2 Material Network
Fig. 2 Material Network
Fig. 3 Output Network
Fig. 3 Output Network

External Python Editor

Setup Environment File

Setup PyCharm to be the external editor for Houdini by specifying it in the Houdini Environment file as follows:

# PYTHON EDITOR
EDITOR = "<ABSOLUTE_PATH_TO>\pycharm64.exe"

Python from PyCharm To Houdini

Accessing Windows > External Python Source Editor will open a Python file in PyCharm titled __python_source_editor.py that can be used to input Python for use in the current Houdini session.

image

Configuring PyCharm

Hython to PyCharm

hython.exe location: $HFS/bin

In PyCharm, add the following paths to the Interpreter's Paths collection:

PATH: $HFS/bin
PATH: $HFS/houdini/python3.7libs

Note that the file may be capped by PyCharm's file size limit, but if encountered, can be resolved with this resolution.

To autocomplete the Houdini library, set the following path as a Resource in the Project Structure:

PATH: $HFS/houdini/python3.7libs

hou Module

Classes appended with _swigregister are included in the list simply because the hou module is constructed with swig.

geo = hou.node('obj/geo1')
tx = geo.parm('tx')
tx.eval()
tx.set(5.0)

hou.session SubModule

hou.session is stored in the .hip file

Available under the Windows menu

Functions defined here are stored in the hou.session module

Python in HDAs

Reference the following section for an example of applying Python States in HDAs.

Function defined in PythonModule (Edit Operator Type Properties > Scripts > Event Handler > Python Module) can be accessed in Python using hdaModule()

hou.node("/obj/hda_node").hdaModule().functionName()

External .py files can be added to HDA in this Scripts section via Add File.

Additional Libraries

Guide for installing additional libraries:

  1. Copy get-pip.py file from link to Houdini's Python directory.
  2. Link: https://www.pypa.io/en/latest/

  3. In command prompt shell, navigate to Houdini's Python directory and run copied file to install pip:
  4. python3.7.exe get-pip.py

Source: https://wordpress.discretization.de/houdini/home/advanced-2/installing-and-using-scipy-in-houdini/

Workspace Configuration

User Interface

Viewport Color Schemes Location:

C:\Program Files\Side Effects Software\Houdini <version>\houdini\config

List of schemes:

  • Dark
  • Grey
  • Light

Ref: https://www.sidefx.com/docs/houdini/hom/hou/viewportColorScheme.html

Resources

Houdini Resources

Default Node Colors

The following RGB values are for the default node colors available in the Color Palette for use in the Network View. The palette can be accessed with the C keyboard shortcut. These RGB values can be used with hou.Color(), as shown above in Create & Format Node.

image

Node Shapes

This is used access the available list of node shapes under the Shape Palette for use in the Network View. The shapes can be accessed by way of the Z keyboard shortcut.

Network Editor UI Preferences

List of available UI preferences for a Network Editor pane in a Houdini desktop/session.

Python Resources

Resources

Modules