Results 1 to 18 of 18

Thread: python Maya startup script

  1. #1
    undefined
    Join Date
    Nov 2011
    Posts
    8

    Default python Maya startup script



    Hi
    I want to run a python script whenever i start maya.How this can be done?

  2. #2
    undefined michaeltrainor's Avatar
    Join Date
    Feb 2010
    Location
    San Carlos, CA
    Posts
    9

    Default userSetup.py

    %MAYA_APP_DIR%/scripts/userSetup.py

    %MAYA_APP_DIR% is an environment variable that defines where the root of your chosen Maya data directory is located. Usually defaults to something like C:\User\yourusername\Documents\maya.

    You can write scripts in userSetup.py or call/import others.

  3. #3
    Administrator Rob Galanakis's Avatar
    Join Date
    Jun 2008
    Location
    Reykjavik, Iceland
    Posts
    1,242

    Default

    There are considerations to make whether this is personal (in which case Michael's answer is great) or for distribution, in which case you may want to consider other options.
    Forum Administrator
    www.robg3d.com

  4. #4
    Validator Wolfsong's Avatar
    Join Date
    Mar 2010
    Location
    Sollentuna, Sweden
    Posts
    139

    Default

    You can also have a userSetup.py in each of your script path and they will all get executed one after another at startup.

    When doing this for userSetup.mel, I've found that only the first instance found in the path gets executes (like all other MEL scripts). So users could in this case override your server/P4/SVN located userStartup.mel with a local one... not that good. But as said it's not as big a problem with userSetup.py. Now it all comes down to executing order, and user script folder is among the first ones so any server/P4/SVN located scripts will normally run last (depending on how you add your custom script path to Maya).
    // Erik
    LinkedIn

  5. #5
    Technical Artist
    Join Date
    Jul 2008
    Location
    Austin, TX
    Posts
    676

    Default

    if you launch maya from a customized short cut, or from the command line, you can pass maya a script to execute when it launches. I believe this file has to be a .MEL script, but it can execute python commands within it.

    we use this feature to separate the local userSetup files from the stuff we want to globally distribute to the whole team.

  6. #6
    CG Extraordinaire jawabiscuit's Avatar
    Join Date
    Oct 2009
    Location
    Greenwich, CT
    Posts
    46

    Default

    Quote Originally Posted by vifx View Post
    Hi
    I want to run a python script whenever i start maya.How this can be done?
    I wrote down some stuff about this on my blog a while back. It's more detailed in case you want a better idea of what is possible. Actually I've been wanting to do another installment of this after I have since had lots more experience doing this for personal and studio-wide distribution. Much, much more can be done with python to make something like this a very powerful approach to configure maya. However, your needs are probably pretty simple so I wouldn't overload you with that. Feedback welcome! I want to cater to people who are exploring, and I don't want python to seem intimidating for the beginner to novice group.

    http://www.jonasavrin.com/2011/02/18...-usersetup-py/

  7. #7
    Technical Artist
    Join Date
    Jul 2008
    Location
    Austin, TX
    Posts
    676

    Default

    good stuff, we also ignore userSetup.mel, userSetup.py and maya.env.
    those are still there for individual users to modify if they want certain tools, but we have moved the start-up procedure for maya into source control. We have a batch script that configures the user's environment for all our tools, but one of the things it does is create a new shortcut on the desktop to maya that handles setting up the environment variables and system paths.
    One of the benefits of doing it this way is I still have the original, native maya shortcut avilable as well. If i ever need to isolate bugs or crashes from our tools, i can easily launch a clean, factory version of maya.

  8. #8
    tiny dancer patconnole's Avatar
    Join Date
    May 2011
    Location
    Seattle, USA
    Posts
    199

    Default

    Quote Originally Posted by rgkovach123 View Post
    We have a batch script that configures the user's environment for all our tools, but one of the things it does is create a new shortcut on the desktop to maya that handles setting up the environment variables and system paths.
    One of the benefits of doing it this way is I still have the original, native maya shortcut avilable as well. If i ever need to isolate bugs or crashes from our tools, i can easily launch a clean, factory version of maya.
    This is awesome. Your environment variables are still set to non-factory settings though, when you run the clean Maya though, correct? Or are you resetting them beforehand?

  9. #9
    Technical Artist
    Join Date
    Jul 2008
    Location
    Austin, TX
    Posts
    676

    Default

    The environment variables are only set within the single instance of maya, since we run it through a command shell. Therefore the system itself is never permantly modified and doesn't need to be reset.
    Native Maya and our customized Maya live side by side with no conflicts.

  10. #10
    Administrator Rob Galanakis's Avatar
    Join Date
    Jun 2008
    Location
    Reykjavik, Iceland
    Posts
    1,242

    Default

    There's never a reason to modify persistent global state for your pipeline. There's never a reason to break that rule. Kovach is exhibit A.
    Forum Administrator
    www.robg3d.com

  11. #11

    Default tutorial?

    I am very interested in figuring out the tool deployment technique rgkovach123 mentioned in his posts. rgkovach123 could you or anyone else point me to a tutorial or some docs that might help me to deploy environment var and such as described above, without affecting a default Maya startup.

    Thanks for any pointers to where to look and read.

  12. #12
    rm -rf / TheMaxx's Avatar
    Join Date
    Mar 2009
    Location
    Lake Forest
    Posts
    520

    Default

    any ideas as to why userSetup.py wouldn't be called? It's placed in:

    C:\Users\username\Documents\maya\2013.5-x64\scripts

  13. #13

    Default

    it always gets called, it just gets called really early while Maya is loading so it can't really effect the startup scene, since the scene isn't fully constructed yet.

  14. #14
    Technical Artist
    Join Date
    Jul 2008
    Location
    Austin, TX
    Posts
    676

    Default

    we basically have three steps for distributing maya tools. None of which affect the default installation of maya or any of it's environment variables.

    First we have a simple python program that collects information about the environment - where perforce, where maya is, etc. This program also creates a new desktop shortcut for maya with a unique name so it isn't confused with the regular desktop shortcut. This program isn't run very often, basically each time a new version of the tools are pushed to the team.

    Second we have a special MEL script simply called mayaStartupConfig.MEL. This MEL file just calls python scripts which are deferred until maya is idle.

    Third we have a second python program that is called. This is what the new Maya shortcut runs instead of the maya.exe. This python program sets the Maya Env Vars and then calls maya.exe with -c flag pointed to mayaStartupConfig.MEL file. This basically allows you to give maya another script to run when it loads in addition to the userSetup files.

    So now i have two desktop shortcuts for Maya, one that is custom and one that is native. Individuals users can modify maya.env, userSetup.mel, userSetup.py however they like, and they will work under both conditions.

  15. #15
    rm -rf / TheMaxx's Avatar
    Join Date
    Mar 2009
    Location
    Lake Forest
    Posts
    520

    Default

    thanks passerby, I was using prints to test and i guess it gets executed earlier than the script editor takes over stdout.

  16. #16
    program Theodox's Avatar
    Join Date
    Mar 2012
    Location
    Seattle
    Posts
    1,107

    Default

    I just use a userSetup.py that checks our distribution server for the latest tools (they live there as zip). If needed it downloads the zip and includes it in sys.path. If I want to opt out for any reason I just remove the custom userSetup.

  17. #17
    program Theodox's Avatar
    Join Date
    Mar 2012
    Location
    Seattle
    Posts
    1,107

    Default

    I just use a userSetup.py that checks our distribution server for the latest tools (they live there as zip). If needed it downloads the zip and includes it in sys.path. If I want to opt out for any reason I just remove the custom userSetup.

    In passing I'd point out that using p4 directly is not ideal unless you oblige everybody to force-sync your distribution files every time. You'll always have .pyc files lying around (which usually are not checked in) so it's possible have 'phantom' modules left over from earlier runs which may get picked up and executed, leading to a lot of head scratching as you see errors that literally dont exist in your python files but do exist in the pyc. You can either check in PYCs (bad if you have to support multiple OSs or bit depths -- and I'm not sure python respects the flags) or delete them before your sync

  18. #18
    undefined
    Join Date
    Nov 2008
    Location
    Malmö / Sweden
    Posts
    7

    Default Sounds like a nice windows setup

    How would this translate for a OSX setup?

    Quote Originally Posted by rgkovach123 View Post
    we basically have three steps for distributing maya tools. None of which affect the default installation of maya or any of it's environment variables.

    First we have a simple python program that collects information about the environment - where perforce, where maya is, etc. This program also creates a new desktop shortcut for maya with a unique name so it isn't confused with the regular desktop shortcut. This program isn't run very often, basically each time a new version of the tools are pushed to the team.

    Second we have a special MEL script simply called mayaStartupConfig.MEL. This MEL file just calls python scripts which are deferred until maya is idle.

    Third we have a second python program that is called. This is what the new Maya shortcut runs instead of the maya.exe. This python program sets the Maya Env Vars and then calls maya.exe with -c flag pointed to mayaStartupConfig.MEL file. This basically allows you to give maya another script to run when it loads in addition to the userSetup files.

    So now i have two desktop shortcuts for Maya, one that is custom and one that is native. Individuals users can modify maya.env, userSetup.mel, userSetup.py however they like, and they will work under both conditions.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •