So I'm working on a plugin composed of numerous python files and am struggling to get grip on the module system which is in place. I've been looking at this [www.sidefx.com] page to try and figure it out with limited success. For example I've got 2 extra files alongside the python module file which look like this:
However, running them I end up with an AttributeError from bar.py: ‘module’ object has no attribute ‘foo’
Why is this? does createModule only work inside the PythonModule file? is the access method in bar.py correct? I'm just a bit puzzled with the whole thing…
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.
Graham Thompson, Technical Artist @ Rockstar Games