Python Maya startup script

maya

#21

The order actually follows sys.path, you can actually find the userSetup.py behavior in maya.app.startup.basic.executeUserSetup, in fact if you need to rerun userSetup for some reason you can call that function and it will do so.

You are correct that this all runs well before the GUI.

However, I would do this a bit differently, instead of passing a string into executeDeferred you can hand it the function object and it will call it for you at the proper time. The nice thing about this is you can pass *args, **kwargs along with it.

import maya

def yourMethodName(standalone=False):
    #do python stuff here once GUI’s loaded.
    pass

maya.utils.executeDeferred(yourMethodName, standalone=True)

#22

Thanks! That’s much cleaner. I was shown passing the method as a string, and assumed from lack of testing time, it was like old mel eval, and never questioned it this entire time.

(also looks like I need to learn how to format my responses on here for legibility)

Any other tricks for testing startup without shutting down maya and reopening it?


#23

The best trick is to make sure that your startup proper is as short and simple as humanly possible. It should only handle making sure the rest of your code is available for import and then kickoff whatever code you need by calling a single function. Then you can test the pieces in isolation