Question about organizing and utilizing custom python plugin libraries
-
That title might be a bit confusing. Allow me to try and explain.
I have some ideas for a few different commandData plugins. The plugins pertain to extracting Joint Weight Data from certain deformers. For example extracting a skinned ffd deformer into joint weights. Extracting the effects of a delta mush deformer into joint weights, extracting a spline deformer to joint weights, etc.
My thought is to make X number of different commandData plugins for each instance, however all of these plugins use a lot of shared functions that I have written to do sort of generalized steps of each of these(Get the weight tag from an object, Creating weight maps from something, etc). So my question is how do I organize this in such a way so that I can have my shared libraries separate that each command data plugin could access without each plugin needing all the duplicate functions in there? I hope that makes some sense.
It's kind of like being able to do:
import myLib myLib.myFunction()
But I am not sure how to manage that across multiple plugins that will be source protected, and how to go about distributing that.
I hope this make some sort of sense.
-
Hey @BretBays,
Thank you for reaching out to us. You might want to have a look at the Python Libraries Manual. Since Cinema 4D 2024.0 there is also mxutils.LocalImportPath which automates injecting module paths and reloading such imported modules (I probably should update the Python libraries manual).
The "flaw" of all these approaches is that while you still encrypt your plugins pyp file, the imported module(s) py file(s) will not and cannot be encrypted. You can either ship your common functions unencrypted or develop your plugin as a multi module solution (so that you do not have to replicate your code across plugins) and then package up the plugin into a singular file. There are some Python tools like
pysconcat
andpymerger
which can help you with that. But you should be aware that these can fail when you have complex dependencies. You could also serve the py-cache of your modules, but that will not really stop anyone who wants to read your code.Cheers,
Ferdinand