Jump to content

[Solved] External python script in HDA modules


sant0s81

Recommended Posts

Hello,

I once saw a tutorial that explained, how to import another python script inside a HDA - but I dont find it anymore.

On the screenshot I try to explain what I mean.

I am not sure anymore if it was import xyz from xyz or something like that.

Could someone give me a hint? :)

Thanks alot,
sant0s

import_external_file.thumb.jpg.1ecc46f207e92ae46fa094ef50976547.jpg

 

 

Edited by sant0s81
Link to comment
Share on other sites

To import a specific script in Python you need to append the folder where it is to the python path (the path contains all the paths to the different modules it loads). You can do it using the sys module :

import sys

sys.path.append("/path/to/the/folder/where/my/script/is/myscript.py")

import myscript

And if you want to import just a specific function from your file and not all the file :

import sys

sys.path.append("/path/to/the/folder/where/my/script/is/myscript.py")

from myscript import myfunction 

 

Cheers,

  • Like 2
Link to comment
Share on other sites

If I understand correctly this question: How import into the PythonModule a Custom Script stored in HDA ?

Like your screenshot, to import all functions stored into "import_that_script" inside the PythonModule.

There is an answer in docs: https://www.sidefx.com/docs/houdini/hom/hou/HDAModule.html

Quote

 

If you find that a digital asset has too much Python code to store in one module, it’s possible to create submodules. For example, if you want to create a submodule named bar, put its source code in a new digital asset section (say, "bar_PythonModule"). Then, from the Python Module section, you can write the following:


import toolutils
bar = toolutils.createModuleFromSection("bar", kwargs["type"], "bar_PythonModule")


 

So in your case in the PythonModule section:

import toolutils
myscript = toolutils.createModuleFromSection("myscript", kwargs["type"], "import_that_script")

Then, you can execute a function as imported module do: myscript.myfunction()

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