What the stuff in those articles does is just to make sure that you can bundle up a bunch of python and distribute it as a unit – it’s an alternative to installers.
So : you have a directory with all your scripts in it. If you run keystone on it, they all get bundled up into a zip file and that gets hidden inside the mel.
When you run the mel, the zipfile is extracted to a hidden directory and its contents go onto your PATH – so if you include a module in that folder, you’ll be able to import it in your running maya session. If you had a file in the zip called foo.py
, launching the keystone mel file will allow you to import foo
from the maya listener.
If you have a __main__.py
in the root of the folder you’re zipping up, then it will run when you launch the mel file. So, if you add a __main__.py
like this:
import foo
foo.do_something()
then the foo module will be imported and foo.do_something()
will be run on startup. If foo.do_something()
wants to add a menu or something like that it’s welcome to do so ; this code should just run whenever Maya is started using the keystone mel file .
A main part of the design is that it’s opt-in – if you run the mel it works, if you just run maya nothing special happens. That makes it easy to distribute and ‘uninstall’. A good way to manage it on windows is to make a shortcut which actually runs the mel file and another which does not – that way you can choose at startup.
Here’s a sample that illustrates the process: https://www.dropbox.com/s/5st06fwiy221gax/menu_test.py.mel?dl=0
If you download that, and either double-click it or run maya.exe c:/path/to/menu_test.py.mel
from the command line, it should work. You can see the actual files in your maya scripts folder – there will be folder there called ‘keystones’ and in it a zip file called 'menu_test.py.mel.zip` – that zip file shows you how the files were laid out