Importing Python Modules

   1486   1   1
User Avatar
Member
191 posts
Joined: Oct. 2018
Offline
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..
User Avatar
Member
39 posts
Joined: Jan. 2012
Offline
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)
www.aaronauty.com
  • Quick Links