script_generator.py¶
Public interface for generating Houdini scripts.
This module provides high-level functionality for generating menu scripts, action button scripts, and managing script templates in Houdini Digital Assets. It abstracts away the implementation details while providing a clean, type-safe API.
Example
generator = ScriptGenerator.create("menu") script = generator.generate_script( ... category="group_selection", ... name="single_group_type", ... options={"option1": "hou.geometryType.Points"} ... )
Classes:
Name | Description |
---|---|
ScriptGenerator |
High-level script generation interface |
HDAScriptManager |
Script generation in HDAs |
HDAScriptManager
¶
Manages script generation in Houdini Digital Assets.
This class provides high-level functionality for handling script generation UI and script creation in HDAs.
Attributes:
Name | Type | Description |
---|---|---|
node |
Node
|
The HDA node containing the UI |
generator |
ScriptGenerator
|
The script generator instance |
Methods:
Name | Description |
---|---|
update |
Updates UI based on current selections |
generate |
Creates script from current UI values |
get_node |
Returns the associated HDA node |
Example
node = hou.node('/obj/myHDA') script_ui = ScriptGenerator(node) script_ui.update() result = script_ui.generate()
Raises:
Type | Description |
---|---|
ValueError
|
If initialization fails |
RuntimeError
|
If script generation operations fail |
Source code in core/script_generator.py
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 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 |
|
node: hou.Node
property
¶
Get the associated HDA node.
Returns:
Type | Description |
---|---|
Node
|
hou.Node: The HDA node containing the script generation UI |
Raises:
Type | Description |
---|---|
RuntimeError
|
If node reference is invalid or None |
__init__(node)
¶
Initialize with HDA node.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node
|
Node
|
HDA node containing script generation UI. Must be a valid Digital Asset node. |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If node is None or not an HDA node |
TypeError
|
If node is not of type hou.Node |
Source code in core/script_generator.py
generate_script()
¶
Generate script based on current UI selections.
Creates a Python script by processing the current parameter values in the HDA UI and generating appropriate script content using the configured generator.
Returns:
Type | Description |
---|---|
Optional[str]
|
Optional[str]: The generated script if successful, None if generation fails due to invalid selections or missing required values. |
Raises:
Type | Description |
---|---|
ValueError
|
If required parameters are missing or invalid |
RuntimeError
|
If script generation fails |
Example
script = hda.generate_script() if script: ... hou.node('/obj/geo1').setParms({'script': script})
Source code in core/script_generator.py
update_ui()
¶
Update the HDA UI based on current selections.
Updates parameter values, enables/disables fields, and refreshes menu items based on the current state of UI selections in the HDA.
Raises:
Type | Description |
---|---|
RuntimeError
|
If UI parameters cannot be updated |
ValueError
|
If parameter values are invalid |
Source code in core/script_generator.py
ScriptGenerator
¶
High-level interface for script generation.
This class provides methods to generate Houdini scripts from templates while handling configuration loading and validation.
Example
generator = ScriptGenerator.create('menu') script = generator.generate_script('groups', 'by_type', { ... 'type': 'points' ... })
Source code in core/script_generator.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 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 |
|
__init__(impl)
¶
Initialize with implementation object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
impl
|
ScriptGeneratorImpl
|
Implementation object containing template handling logic |
required |
Returns:
Type | Description |
---|---|
None
|
None |
Raises:
Type | Description |
---|---|
TypeError
|
If impl is not a ScriptGeneratorImpl instance |
ValueError
|
If impl is None |
Source code in core/script_generator.py
create(script_type, config_path=None)
classmethod
¶
Create a script generator of the specified type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
script_type
|
ScriptType
|
Type of scripts to generate ("menu" or "action") |
required |
config_path
|
Optional[Path]
|
Optional custom path to config file |
None
|
Returns:
Type | Description |
---|---|
ScriptGenerator
|
Configured script generator |
Raises:
Type | Description |
---|---|
ValueError
|
If script_type is invalid |
ConfigurationError
|
If config loading fails |
Example
generator = ScriptGenerator.create('menu') generator.generate_script(...)
Source code in core/script_generator.py
generate_script(category, name, options)
¶
Generate a script from a template.
Creates a Python script by applying the provided options to the specified template.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
category
|
str
|
Template category (e.g. 'tool', 'shelf', 'node') |
required |
name
|
str
|
Template name to use for generation |
required |
options
|
Dict[str, Any]
|
Dictionary of option values to apply to the template. Keys must match template parameter names. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The generated script code ready for use in Houdini |
Raises:
Type | Description |
---|---|
ValidationError
|
If script generation fails due to: - Invalid template category or name - Missing required options - Option value validation failures |
KeyError
|
If template not found |
Example
options = {'name': 'myTool', 'type': 'delete'} script = generate('tool', 'basic', options)
Source code in core/script_generator.py
get_categories()
¶
Get available script categories.
Retrieves all supported script template categories from the configuration.
Returns:
Type | Description |
---|---|
List[str]
|
List[str]: List of available script categories. Example: ['node', 'tool', 'shelf'] |
Raises:
Type | Description |
---|---|
RuntimeError
|
If no categories are configured |
Source code in core/script_generator.py
get_template_info(category, name)
¶
Get detailed information about a template.
Retrieves metadata and configuration details for a specific template.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
category
|
str
|
Template category to look in |
required |
name
|
str
|
Name of the template to get info for |
required |
Returns:
Type | Description |
---|---|
Dict[str, any]
|
Dict[str, Any]: Dictionary containing template metadata including: - description: Template description - parameters: Template parameters - defaults: Default values - options: Available options |
Raises:
Type | Description |
---|---|
ValidationError
|
If template not found |
KeyError
|
If category doesn't exist |
Source code in core/script_generator.py
get_templates(category)
¶
Get available templates in a category.
Retrieves all template names available within the specified category.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
category
|
str
|
Category to get templates for. Must be a valid category name. |
required |
Returns:
Type | Description |
---|---|
List[str]
|
List[str]: List of template names available in the specified category. Example: ['delete_unused', 'create_group', 'export_fbx'] |
Raises:
Type | Description |
---|---|
KeyError
|
If category doesn't exist |
ValueError
|
If category is empty or None |
Source code in core/script_generator.py
create_action_script(category, name, options)
¶
Create an action button script from a template.
Creates a Python script for a Houdini action button based on the specified template and options. Handles proper formatting and validation for button script requirements.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
category
|
str
|
Template category ('tool', 'shelf', etc.) |
required |
name
|
str
|
Template name to use for generation |
required |
options
|
Dict[str, Any]
|
Configuration options for script generation. Values depend on the template requirements. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The generated Python script code ready for use in Houdini |
Raises:
Type | Description |
---|---|
ValidationError
|
If script generation fails due to invalid options |
KeyError
|
If template or category not found |
Example
script = create_action_script( ... "file_operations", ... "open_in_explorer", ... {"option1": "hip"} ... )
Source code in core/script_generator.py
create_menu_script(category, name, options)
¶
Create a menu script from a template.
Convenience function for quick menu script generation without creating a generator instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
category
|
str
|
Template category |
required |
name
|
str
|
Template name |
required |
options
|
Dict[str, str]
|
Dictionary of option values |
required |
Returns:
Type | Description |
---|---|
str
|
Generated menu script |
Example
script = create_menu_script( ... "group_selection", ... "single_group_type", ... {"option1": "hou.geometryType.Points"} ... )
Raises:
Type | Description |
---|---|
ValidationError
|
If template or options are invalid |