sant0s81 Posted July 10, 2020 Share Posted July 10, 2020 (edited) 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 Edited July 11, 2020 by sant0s81 Quote Link to comment Share on other sites More sharing options...
DonRomano Posted July 10, 2020 Share Posted July 10, 2020 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, 2 Quote Link to comment Share on other sites More sharing options...
sant0s81 Posted July 10, 2020 Author Share Posted July 10, 2020 @DonRomano thank you, works perfect. Quote Link to comment Share on other sites More sharing options...
fsimerey Posted July 10, 2020 Share Posted July 10, 2020 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() 1 Quote Link to comment Share on other sites More sharing options...
sant0s81 Posted July 10, 2020 Author Share Posted July 10, 2020 @fsimerey Great, thats actually what I was trying - but than stored the script in a file and used the technique mentioned above. But yes, thats what I was thinking. Thx! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.