Search - User list
Full Version: Importing Python Modules
Root » Technical Discussion » Importing Python Modules
krueger
I'm saving out some commonly used functions into a custom python module but it seems like every different place in Houdini I want to use them, I have to import the module separately. For example, in a shelf tool I'll have to import it and also in a node parameter I'll have to import it there too, so it's not globally accessible.

1. Is there a way to import a module that's globally accessible everywhere?
2. If not, would it become problematic if dozens of parameters or tools being used by many artists keep trying to import/reload the module constantly?
3. If a parameter has a python expression importing the module to run some function, is it only going to import when the node is cooked?

Basically I'm trying to figure out if having the functions on disk somewhere will be efficient instead of keep the python code in the tools or parameters..
aaronauty
You can use hou.session to create python accessible anywhere in the current session. It's good for global functionality.
https://www.sidefx.com/docs/houdini/hom/hou/session.html [www.sidefx.com]

You can write to the session module like this;
hou.appendSessionModuleSource(my_module)
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB