Graham Thompson

graham

About Me

Expertise
Not Specified
Location
United States

Connect

Recent Forum Posts

Using multiple python files as modules Nov. 2, 2022, 1:23 p.m.

Personally I would really avoid doing this kind of thing. If you have a lot of code better organized in different modules I'd recommend just using proper python modules on disk somewhere. If they really need to be encapsulated within the asset then I'd probably bite the bullet and just put all the code in the PythonModule, no matter how unruly it may be.

Most likely the original poster's issue is that there's basically circular importing going on. The main PythonModule is "importing" foo which is attempting to "import" bar which then tries to access foo from the main module which is still in a loading operation. In their case it would have probably been better for bar to access foo by also creating it from source internally since these aren't real modules and it would avoid what's probably the issue. Unless of course there are global variable things involved in foo then you're out of luck.

HDA python global variables Oct. 26, 2022, 2:33 p.m.

Good times. I think this original post preceeded the ability to stash data on hou.Node instances. There's definitely different ways you could do this now:

As a direct replacement for using a parameter, you can now more easily take your binary data string and use the Data Blocks added in recent versions. This basically allows you attach the binary string directly to the node instance that will persist sessions and would also be brought along if you copy the node.
>>> some_data = range(10)
>>> data_str = pickle.dumps(some_data)
>>> hou.node('/obj/subnet1').setDataBlock("my_range", data_str, "")
>>> some_data == pickle.loads(hou.node('/obj/subnet1').dataBlock("my_range"))
True

If you just need your data available in the current session and don't need it to persist you can of course now just take your Python object and assign it directly as cached user data on the hou.Node instance. You could also stash the above string as standard user data as well.

Another alternative would be to use the Data parameter type and encode your data in geometry and then attach it to a node that way. If your data is a simple key/value dict you could also use the Key/Value parameter type and be able to visualize/edit it in the interface.

Python Source Editor does not save when I close Houdini Oct. 14, 2022, 3:13 p.m.

Putting all your code in an external module is the best way to go about it so that all files can access it. In terms of reloading, you can manually run a Python reload on your module when you've made changes that you want to pick up immediately.

Alternatively, you could shove it all into an HDA's PythonModule section (so that you can edit in Houdini and changes happen immediately) and refer/execute it from there via some convoluted means as long as the HDA is installed in the session.