hou.expressionGlobals
function
Return the globals dictionary used by the parameter expression evaluation namespace.
Usage
expressionGlobals() → dict
When Houdini evaluates a Python expression inside a parameter, it uses a separate namespace. This way, Houdini can run from hou import * and from hou.session import * in that namespace, allowing you to drop the hou. and hou.session. prefixes in your expressions, and the global namespace does not get polluted.
In Python, namespaces are stored as dictionaries. This function returns the dictionary for the Python parameter expression namespace. It is analagous to the builtin globals function, which returns you the dictionary for the current namespace.
You might use this function from the pythonrc.py file to set up Python functions that can be called from any Python parameter expression. For example, if you put your functions in a module called expr, you might put the following in pythonrc.py:
import expr hou.expressionGlobals()['expr'] = expr
Then, from a Python expression, you could write expr.foo(), where foo is a function defined in your expr module.
You can also use this dictionary with Python’s exec statement. The following example also imports the expr module into the both the global and expression namespaces:
code = compile("import expr", "<generated_code>", "exec") exec code exec code in hou.expressionGlobals()
See Python Parameter Expressions for more information on using Python expressions in parameters. See Session Independent Scripts for more information about pythonrc.py.