Jump to content

Import python to source editor


onkel_eilert

Recommended Posts

Hi

 

I'm trying to import an external python script into the source editor. I have gotten it to work before but have forgotten what I did :huh: . Any tips? Guessing it is the hou.setSessionModuleSource, but not much help from the docs. So any help would be appreciated. 

 

Thanks.

Link to comment
Share on other sites

If you want to straight up replace the contents of the hou.session module with the contents of an external file then hou.setSessionModuleSource() is the way to do it. The more likely scenario is needing to use an external Python script or library within the hou.session module which can be done by appending search paths. An example is below.

import sys
sys.path.append('/scripts/houdini')

After doing that you'll be able to import libraries in /scripts/houdini directory, or whatever directory you choose. There's an environment variable to set this too but I'm not sure how that works with the Python environment in Houdini.

Link to comment
Share on other sites

That's not really what the hou.session module is for. If you need access to something every time you open Houdini it should be in the toolbar or in the 123.py or 456.py file. If you want to set it with hou.setSessionModuleSource() you literally put the source code you want for the argument. If that's an external file then it needs to be read in first.

f = open('/home/luke/scripts/test.py', 'r')
source = f.read()
hou.setSessionModuleSource(source)
f.close()
  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...