nodes.py¶
Node manipulation utilities for Houdini.
This module provides functions for creating, modifying, and managing Houdini nodes. It includes utilities for customization, replacement, and network building from templates.
Classes:
Name | Description |
---|---|
NetworkBuilder |
Builds node networks from JSON configurations |
Functions:
Name | Description |
---|---|
customize_node |
Apply common customizations to nodes |
replace_with_null |
Replace nodes with null nodes |
NetworkBuilder
¶
Builds Houdini node networks from JSON configurations.
This class handles the creation of node networks based on JSON template definitions, including proper node creation, parameter setting, and connection management.
Attributes:
Name | Type | Description |
---|---|---|
parent |
Parent node for network creation |
|
_created_nodes |
Dict[str, Node]
|
Dictionary mapping node names to created nodes |
Example
builder = NetworkBuilder(hou.node('/obj/target_node')) last_node = builder.build_from_template("my_template")
Since: 1.0.0
Source code in utils/nodes.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 |
|
__init__(parent_node, reference_node=None, output_node=None)
¶
Initialize with parent node for network creation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parent_node
|
Node
|
Parent node for network creation |
required |
reference_node
|
Node
|
Node that is referenced if name isn't supplied in node data. |
None
|
output_node
|
Node
|
Node to use as output if not specified in template |
None
|
Source code in utils/nodes.py
apply_remap(target_string, remap_dict=None)
¶
Replace template tokens with actual values using remap dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target_string
|
str
|
String to replace tokens in |
required |
remap_dict
|
Dict[str, str]
|
Dictionary mapping old values to new strings |
None
|
Returns:
Type | Description |
---|---|
str
|
String with tokens replaced |
Source code in utils/nodes.py
build_from_template(template_name, remap_dict=None)
¶
Build a network from a named template in the config file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
template_name
|
str
|
Name of template in example_networks.json |
required |
remap_dict
|
Dict[str, str]
|
Dictionary mapping old node names to new names. Used to replace template tokens with string values. Applies to node names and string parameter values. |
None
|
Returns:
Type | Description |
---|---|
Optional[Node]
|
The last created node or None if build fails |
Raises:
Type | Description |
---|---|
ValueError
|
If template name is not found |
Notes
- Creates sticky note if template includes description
- Maintains node connections defined in template
- Preserves node positions and relationships
Since: 1.0.0
Source code in utils/nodes.py
customize_node(node, pos=None, color=None, shape=None, comment=None)
¶
Apply common customizations to a node.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node
|
Node
|
Node to customize |
required |
pos
|
Optional[Vector2]
|
New position vector |
None
|
color
|
Optional[Color]
|
New color |
None
|
shape
|
Optional[str]
|
New node shape name |
None
|
comment
|
Optional[str]
|
New comment text |
None
|
Example
node = hou.node('/obj/geo1') customize_node( ... node, ... pos=hou.Vector2(0, 0), ... color=hou.Color((1, 0, 0)), ... shape="rect", ... comment="Modified node" ... )
Notes
- Only applies customizations for non-None arguments
- Comments are automatically displayed when set
Since: 1.0.0
Source code in utils/nodes.py
replace_with_null(node, null_name)
¶
Create a null output node and return that if the current node isn't a null.
Creates a null node connected to the input node's output and positioned below it. If the input node is already a null, returns it unchanged.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node
|
Node
|
Node to potentially replace |
required |
null_name
|
str
|
Name for the null node |
required |
Returns:
Type | Description |
---|---|
Node
|
Either the original node if it's already a null, or the new null node |
Example
geo = hou.node('/obj/geo1') null = replace_with_null(geo, 'OUT_geo')
Notes
- Positions null node 0.5 units left and 1 unit below input node
- Does not delete or modify the original node
- Returns existing null if one with the same name exists
Since: 1.0.0