Jump to content
Sign in to follow this  
faxingberlin

HDA - Import Python Module from extra files

Recommended Posts

Hello, I want to embed my python scripts in HDA.

So, I add test.pyc file to Extra Files Tab. And I want to import this PythonModule in Scripts Tab.

I try to this via hou.readFile("opdef:Sop/hdaname?test.pyc"), but this cannot read pyc binary file.

Is there any way to import python module in extra file?

Share this post


Link to post
Share on other sites
On 2019-07-09 at 7:04 PM, faxingberlin said:

Hello, I want to embed my python scripts in HDA.

Just copy paste your code into a PythonModule, why do you need complicate things with embedding a pyc file?

Using pyc files has some benefits, but only in certain rare circumstances. If your intent is to hide the source code...well.. is it really worth it? pyc files can be easily disassembled. If you want to confuse users so they couldn't figure out your algorithm you could use a python code obfuscator like this one: https://liftoff.github.io/pyminifier/

  • Thanks 1

Share this post


Link to post
Share on other sites

there are some ways to use external files.

one way is to load Your script into the hda in the Scripts tab. and then You can access it  with

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

you can then access the methods by

pwd().hdaModule().bar....

if I remember right, stalkerx777, explained this to me some time ago, thanks again :)

this works really well

Another way is to use the python2.7libs folder in a houdini path folder or in You houdini home directory

every python script stored there can be imported as a module

Share this post


Link to post
Share on other sites
8 hours ago, Stalkerx777 said:

Just copy paste your code into a PythonModule, why do you need complicate things with embedding a pyc file?

Using pyc files has some benefits, but only in certain rare circumstances. If your intent is to hide the source code...well.. is it really worth it? pyc files can be easily disassembled. If you want to confuse users so they couldn't figure out your algorithm you could use a python code obfuscator like this one: https://liftoff.github.io/pyminifier/

Thanks. I see the link that you attached. This is awesome too!

At this time, I want to know how to execute binary files( pyc is just a example ) using hou.readFile method not to hide them.

I know hou.readFile method read file as string. I cannot import and execute them from HDA extra files not only py and pyc.

So, I think just execute py code from string and pyc binary code from string.

I found execute pyc binary by using imp, marshal module. It works perfectly.

https://mail.python.org/pipermail/chicago/2007-August/002498.html

I just wanted to know if there was a way to do this.

I agree with the best way is just copy code to python module in HDA.

Edited by faxingberlin

Share this post


Link to post
Share on other sites
1 hour ago, sanostol said:

there are some ways to use external files.

one way is to load Your script into the hda in the Scripts tab. and then You can access it  with


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

you can then access the methods by


pwd().hdaModule().bar....

if I remember right, stalkerx777, explained this to me some time ago, thanks again :)

this works really well

Another way is to use the python2.7libs folder in a houdini path folder or in You houdini home directory

every python script stored there can be imported as a module

 

This is really good to import python module from external files. But extra files in HDA can load only using hou.readFile method.

Thank you.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×