| On this page |
Overview ¶
Context options are useful for scene-specific variables. For example, you can create a render_quality variable, and reference it in all your render nodes, and a shot_name string that you overlay on all non-final renders.
You can create context options using the Context Options Editor or Python scripting, and then use them in expressions or in Python.
This can be particularly useful when you're using the same HIP file to render multiple shots. You can set up variables with shot-specific values, and change the variables when you change which shot you're working on.
Internally, context options can store either floating point number or string values, keyed to an internal name string. However, they also let you associate a “configuration string” with each option. The Context Options Editor uses this string to store extra information such as a human-readable label, an order, and a user interface type.
You can reference context option values in expressions using @name. For example, if you create an option with the internal name render_quality, you could set the Quality parameter of your main render node to @render_quality and the Quality of a preview render node to @render_quality / 2.
You can also create and read context option values in Python scripts using hou.setContextOption() and hou.contextOption().
Some global context options are generated and maintained by Houdini. Configure the Editor Preferences to list these in the Context Options Editor. These “automatic” context options can be queried and modified like any other context option, and they can be overridden by individual nodes to alter their input’s cook context. But deleting such a context option will only clear the overridden value. The context option will still exist, but it will be once again controlled by Houdini. See hou.isAutoContextOption() for a list of these automatic options.
Additional context options are saved with the HIP file. A newly created HIP file has no context options aside from the automatic ones. If you always want to start new files with a default set of context options, you can export|#hom] the context options as a JSON file and import them in the 456.py HIP file creation script.
Context options editor ¶
| To... | Do this |
|---|---|
|
Open the Context Options Editor window |
Choose Edit ▸ Context Options. |
|
Open the Context Options Editor as a pane tab |
In the pane where you want the editor, click the |
|
Add a new context option |
Click the |
|
Delete an option |
Click the option and then either click the |
|
Edit an option’s configuration |
Click an option’s Note When you edit a label, if the option still has a generic internal name, the editor automatically changes the option’s internal name to match the label (it converts the label to lowercase and replaces spaces with underscores). This only happens once. After that, if you want to change an option’s internal name, you can use the edit window. |
|
Edit an option’s value |
Click and edit the values (under the Value heading) beside their context option. |
|
Change the order of options in the editor interface |
Drag the option’s row up or down in the table. |
|
Undo and redo changes |
|
|
Adjust the Context Options Editor preferences |
Click the |
|
Update the editor with changes made outside the editor |
Click the For example, if you create a new context option using hou.setContextOption(), you must reload the editor to show the new option. |
|
Export the current context options (including configuration) to a JSON file |
Click the Export button in the lower-right corner and choose the file to which you want to export. |
|
Import context options from a JSON file |
Click the Import button in the lower-right corner and choose the file you want to import. Note If the scene file already has context options, Houdini asks if you want to clear them before importing or merge the imported options over the existing options. |
Using context options ¶
-
In parameter expressions, you can use the value of a context option with
@name. -
In a Python script, you can get the value of a context option with hou.contextOption().
Option configuration ¶
Click a context option’s Edit button to open its edit window.
Similar to other elements in Houdini such as parameters, context options have an internal name (the name you use in @name expressions and scripting) and a label (the human-readable name that appears in the Context Options Editor user interface).
Label
The human-readable label for this option when it appears in the Context Options Editor.
Name
The internal name you use for this option in @name expressions and scripting.
Safe Name
As of Houdini 22.0, new context options in new .hip files are safe by default. For backwards compatibility, turn on this parameter in older .hip files to enforce the rule that the Name can be made up of only alphanumeric characters and underscores. If an older .hip file has a number sign (#) in the Name for example, the symbol instead populates as an underscore.
Type
File Path
A (platform-native) file path string. The interface is a text box with inline auto-completion and a browse folder button.
Float Slider
A number within a range. The interface is a text box and slider. You can set up the range and choose whether the user can enter values outside the range’s minimum and/or maximum.
Integer Slider
A whole number within a range. The interface is a text box and slider. You can set up the range and choose whether the user can enter values outside the range’s minimum and/or maximum.
Note
The value is not really an integer: number values in context options are always stored as floating point. The user interface of this type restricts its values to whole numbers, but that number is still stored internally as a float.
Node Path
A Houdini node path string. The interface is a text box with inline auto-completion.
Number
A freeform number. The interface is a text box. You can set up the range and choose whether the user can enter values outside the range’s minimum and/or maximum.
String
A freeform string. The interface is a text box.
Note
The Text type, which is available when you turn on Show Deprecated Types in Menus, shares this description.
Toggle
A value of either on or off. The interface is a toggle.
Note
The Checkbox type, which is available when you turn on Show Deprecated Types in Menus, shares this description.
Heading
Shows its label in large type that spans both columns in the Context Options Editor. Use this type to organize your context options into sections.
File Pattern
The pattern that determines which file types to display in the folder browser. Enter an asterisk (*) to display all file types.
Minimum and Maximum usually set the slider or number range, but the user can still manually enter values less than the minimum or greater than the maximum. Turn on Locked to enforce the minimum or maximum on values the user enters manually.
Minimum
The minimum end of the range.
Maximum
The maximum end of the range.
Locked
Prevent the user from entering a value less than the Minimum or greater than the Maximum.
Editor preferences ¶
Click the Preferences button to open the Editor Preferences window.
Show Automatic Options
Lists the global context options that Houdini automatically generates and maintains. If you delete an automatic option in the Context Options Editor, this clears the overridden value but doesn’t delete the option.
Query and override these options using a script or node. See hou.isAutoContextOption() for more information about the automatic options.
Show Column Header
Displays the Context Option and Value headings above their associated columns in the Context Options Editor.
Show Label
Displays the Label (if provided) of each context option.
Show Name
Displays the Name (if provided) of each context option.
Center Name in Column
Centers the Name of each context option in the middle of the Context Option column when Show Label and Show Name are on.
Float Slider Steps
The decimal point of the Value for Float Slider types. For example, a value of 1000 means that you can set a Float Slider context option to a 0.00 value.
Scripting context options ¶
The following HOM functions let you script the values of context options:
You can also script the Export and Import functions from the Context Options Editor:
import contextoptions
# Export all context options in this scene to a JSON file
contextoptions.exportJson("options.json")
# Import context options from a JSON file and merge them over
# any existing options in this scene
contextoptions.importJson("options.json")To clear any existing options before importing, you can just iterate over all existing options and delete them:
for name in hou.contextOptionNames(): hou.removeContextOption(name)