parameters.py¶
Parameter manipulation utilities for Houdini.
This module provides comprehensive utilities for working with Houdini parameters, including type checking, template modification, conditional logic handling, and parameter referencing. It focuses on maintaining parameter relationships while enabling complex modifications.
Functions:
Name | Description |
---|---|
is_parm_of_type |
Check parameter type |
all_parm_templates |
Iterate through all parameter templates |
modify_parm_templates |
Modify parameter templates with consistent naming |
modify_conditionals |
Update parameter conditional expressions |
relative_reference_multiparm |
Create relative parameter references |
reset_script_parms_to_default |
Reset script parameters to defaults |
mass_connect_parameters |
Bulk connect parameters between nodes |
all_parm_templates(group_or_folder)
¶
Get all parameter templates from a group or folder.
Recursively retrieves all parameter templates, including those nested in folders, which aren't accessible through Houdini's default methods.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
group_or_folder
|
Union[ParmTemplateGroup, FolderParmTemplate]
|
Parameter group or folder to search. |
required |
Returns:
Type | Description |
---|---|
None
|
Generator[hou.ParmTemplate]: Generator yielding all parameter templates |
Raises:
Type | Description |
---|---|
TypeError
|
If input is not a ParmTemplateGroup or FolderParmTemplate |
Example
templates = list(all_parm_templates(node.parmTemplateGroup()))
Source code in utils/parameters.py
is_parm_of_type(parm, types=(hou.parmTemplateType.Int, hou.parmTemplateType.Float, hou.parmTemplateType.String))
¶
Check if parameter is of specified types.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parm
|
Parm
|
Parameter to check |
required |
types
|
tuple[parmTemplateType]
|
Tuple of parameter types to check against. Defaults to (Int, Float, String). |
(Int, Float, String)
|
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if parameter matches any of the specified types |
Example
parm = node.parm('tx') is_parm_of_type(parm, (hou.parmTemplateType.Float,)) True
Source code in utils/parameters.py
mass_connect_parameters(node)
¶
NOT FUNCTIONAL YET Prompts the user to select 2 nodes to copy parms between. In a final version of this, it will create a UI to prompt the user with where they can add modifications to the parm names in order to make them match if they don't have the same names.
Source code in utils/parameters.py
modify_conditionals(conditionals, templates, ref_template_dict, created_by_conditionals=None, prefix='', suffix='', replacefrom='', replaceto='', include_only=None, exclude=None, mod_all_conditionals=True)
¶
Process and update parameter conditional expressions.
Analyzes and modifies conditional expressions in parameter templates, handling parameter references and maintaining relationships.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
conditionals
|
Dict[parmCondType, str]
|
Dictionary of conditional expressions |
required |
templates
|
Union[List[ParmTemplate], List[str]]
|
List of templates or parameter names to process |
required |
ref_template_dict
|
Dict[str, ParmTemplate]
|
Dictionary of reference templates |
required |
created_by_conditionals
|
Optional[List[ParmTemplate]]
|
List to store templates created by conditionals |
None
|
prefix
|
str
|
String to prepend to parameter names |
''
|
suffix
|
str
|
String to append to parameter names |
''
|
replacefrom
|
str
|
String to replace in parameter names |
''
|
replaceto
|
str
|
Replacement string for replacefrom |
''
|
include_only
|
Optional[List[str]]
|
List of parameter names to include |
None
|
exclude
|
Optional[List[str]]
|
List of parameter names to exclude |
None
|
mod_all_conditionals
|
bool
|
Whether to modify all expressions |
True
|
Returns:
Type | Description |
---|---|
Dict[parmCondType, str]
|
Dictionary of updated conditional expressions |
Examples:
>>> conds = {hou.parmCondType.DisableWhen: "param1 == 0"}
>>> modified = modify_conditionals(conds, templates, ref_dict,
... prefix="new_",
... mod_all_conditionals=True)
>>> print(modified[hou.parmCondType.DisableWhen])
'new_param1 == 0'
Notes
- Handles both string names and ParmTemplate objects
- Updates parameter references in expressions
- Maintains conditional logic while updating names
- Adds referenced parameters to template list if needed
Since: 1.0.0
Source code in utils/parameters.py
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 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 |
|
modify_parm_templates(group_or_folder, prefix='', suffix='', replacefrom='', replaceto='', folder_name='', folder_label='', folder_type=hou.folderType.Simple, include_only=None, exclude=None, ref_parmtemplate_dict=None, mod_all_conditionals=True, created_by_conditionals=None)
¶
Modify parameter templates with consistent naming and organization.
Processes a parameter template group or folder to modify parameter names and organization while preserving parameter relationships and functionality.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
group_or_folder
|
Union[ParmTemplateGroup, FolderParmTemplate]
|
Template group or folder to process |
required |
prefix
|
str
|
String to prepend to parameter names |
''
|
suffix
|
str
|
String to append to parameter names |
''
|
replacefrom
|
str
|
String to replace in parameter names |
''
|
replaceto
|
str
|
Replacement string for replacefrom |
''
|
folder_name
|
str
|
Name for the containing folder |
''
|
folder_label
|
str
|
Display label for the folder |
''
|
folder_type
|
folderType
|
Type of folder to create |
Simple
|
include_only
|
Optional[List[str]]
|
List of parameter names to include (None = all) |
None
|
exclude
|
Optional[List[str]]
|
List of parameter names to exclude |
None
|
ref_parmtemplate_dict
|
Optional[Dict[str, ParmTemplate]]
|
Dictionary of reference templates |
None
|
mod_all_conditionals
|
bool
|
Whether to modify all conditional expressions |
True
|
created_by_conditionals
|
Optional[list]
|
List to store templates created by conditionals |
None
|
Returns:
Type | Description |
---|---|
FolderParmTemplate
|
Modified folder containing processed parameter templates |
Raises:
Type | Description |
---|---|
ValueError
|
If folder_name or folder_label not provided |
Examples:
>>> # Basic parameter renaming
>>> templates = node.parmTemplateGroup()
>>> modified = modify_parm_templates(templates,
... prefix="mat_",
... folder_name="material_params",
... folder_label="Material Parameters")
>>> # Complex filtering and modification
>>> modified = modify_parm_templates(templates,
... prefix="shader_",
... include_only=["diffuse", "specular"],
... exclude=["*_old"],
... mod_all_conditionals=True)
Notes
- Parameters in conditionals are handled specially:
- Referenced parameters are added even if not in include_only
- Conditional expressions are updated to match naming changes
- Exclusion patterns with * are treated as wildcards
- Parameter references and relationships are maintained
Since: 1.0.0
Source code in utils/parameters.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 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 |
|
relative_reference_multiparm(source_node, target_node, target_mparm_name, parm_name_dict, start_index=1)
¶
Connect source parameters to destination parameters in a multiparm block.
Creates relative references between source and destination parameters and ensures new multiparm entries maintain these connections.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source_node
|
Node
|
Node containing source parameters |
required |
target_node
|
Node
|
Node containing target multiparm block |
required |
target_mparm_name
|
str
|
Name of the multiparm parameter |
required |
parm_name_dict
|
dict
|
Mapping of source to destination parameter names. Format: {"source_parm#": "dest_parm#", "source_parm2#": "dest_parm2#"} |
required |
start_index
|
int
|
Starting index for multiparm. Defaults to 1. |
1
|
Raises:
Type | Description |
---|---|
ValueError
|
If parameters don't exist or are invalid |
RuntimeError
|
If parameter connections fail |
Example
parms = {"scale#": "instance_scale#"} relative_reference_multiparm(src, dst, "num_instances", parms)
Source code in utils/parameters.py
reset_script_parms_to_default(node)
¶
Reset all script parameters to their default values.
Resets parameters with script callbacks to their default script values to ensure proper parameter updating behavior.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node
|
Node
|
Node containing script parameters to reset |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If node is None or invalid |
RuntimeError
|
If parameter reset fails |