Jump to content

sourcing external .py files


borisb2

Recommended Posts

Quick question:

 

I'm running a lot of python snippets (creating specific nodes, ROPS etc.) through a custom menu in houdini. The external python-files are sourced in the MainMenuCommoin.xml via

<label>Submit Caching Job (Non Sequential)</label>
<scriptPath>Y:/_scripts/houdini/submitCachingJob.py</scriptPath>

So far so good.

 

Now I want to create a button on a node in houdini that also calls one of these external scripts. But here I'm a little stuck as I can't figure out how to actually source an external python-script via the buttons callback-script. In these files there are no functions to import, just plain commands to create/connect/set something in houdini.

 

What would be an easy way to source an external python file?

Thanks a lot.

Edited by borisb2
Link to comment
Share on other sites

Thanks. But even if I'd wrap all commands in a function, how would I source that external py-file in the buttons callback script? .. the file is not sitting in the users directoy but on the server.

 

Guess I have to look at the execfile function?

Link to comment
Share on other sites

You could try something like this in your callback script.

import sys; sys.path.append("/path/to/your/python/module"); import your_module; your_module.main()

As Alexey mentioned make sure your code is wrapped into functions otherwise it will only be run once when the module is imported.

 

Cheers,

Dennis

Link to comment
Share on other sites

hmm ... trying:

import sys; sys.path.append("Y:/_scripts/houdini/setMantraOutput"); import setMantraOutput

but I get "No module named setMantraOutput"..

 

The file sits here:

Y:/_scripts/houdini/setMantraOutput.py

 

what am I doing wrong?

Link to comment
Share on other sites

hmm ... trying:

import sys; sys.path.append("Y:/_scripts/houdini/setMantraOutput"); import setMantraOutput

but I get "No module named setMantraOutput"..

 

The file sits here:

Y:/_scripts/houdini/setMantraOutput.py

 

what am I doing wrong?

Read the basics of Python modules. You need to append a path to a folder, not to a file, where python can find your module by name.

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...