import custom module from plugin
-
On 17/10/2016 at 07:09, xxxxxxxx wrote:
Hi all,
This seems like a basic question but I couldn't find any answers here on the forum (correct me if I'm wrong).
I'm writing a shader plugin that will reference another module with all the shader formulas. Is there a way to access this module (formulas.py) when it's in the same folder as the plugin? If I put it there, cinema complains: "ImportError: No module named formulas".
If I put it in the packages dir it does find it, but I would like to keep em together. Here's an example of the directory structure I would like to achieve:+plugins
+myshader
myshader.pyp
formulas.py (also tried .pyp, no succes)I've tried adding an __init__.py, but then cinema doesn't even find the plugin itself anymore.
Any help would be appreciated!Kind regards,
Hermen
-
On 17/10/2016 at 08:52, xxxxxxxx wrote:
Hi, Hermen.
I'm not really sure about your question, but have you seen this thread?
https://developers.maxon.net/forum/topic/8229/10727_best-practice-for-imports -
On 17/10/2016 at 12:18, xxxxxxxx wrote:
Hi dmitry,
To be honest, no, I didn't find that one. But if it's that complicated, I'll guess I leave it just where it is.
But thanks for the find, anyway!regards,
Hermen
-
On 25/10/2016 at 05:04, xxxxxxxx wrote:
Hello All,
I tried to grasp Niklas' code, but I am afraid it is beyond me. But MAXON's Python SDK tells us we can use a simple:dir, file = os.path.split(__file__)
which is certainly more pythonic. And pure python. And only one line...
So I thought I'd post this here, more so because the post above this one is about the same topic, as dmitry pointed out
Regards,
Hermen
-
On 25/10/2016 at 07:33, xxxxxxxx wrote:
Hi Hermenator, what's hard to grasp on the code? You don't need to understand what's happening
in the localimport class if you don't want to.I advise against manually appending paths to sys.path unless you want to make the module available
to the whole Python ecosystem. -
On 25/10/2016 at 10:09, xxxxxxxx wrote:
Hi Niklas,
Well, I had a particular hard time on the second line:
"eJydGctu20bwrq8gkAPJmKXjBr0IZVCkSIGiRQ5B0UMFgqDIpbw1RRK7q9SykX/vzOyTItU4vVjL3ZnZeT/W/DiNQkXNOJ2zQz/"
(Just kidding)But I must say I was mistaken. The page in the SDK refers to a resource folder, ie for bitmaps and other resources. Actually importing a module this way is not possible.
Reason I considered it too much effort is because while still in development I am only going to be using this on my own computer. If time comes to publish this plugin, I think your approach makes sense. And you have even taken the effort of making pre-minified versions, so thank you for that
Regards,
Hermen