lunes, 24 de noviembre de 2014

Adding a Custom Script Folder To Be Loaded On Maya Startup

Now that we have our IDE setup there is one more thing to do: 
we need to tell Maya where to look for our custom scripts.
The method i ve used is basically to create a "userSetup.py" file in my "My Documents\maya\2015-x64\scripts" which was previously empty.

Anything written python wise in that file will run on Maya startup, so i decided to add a path to the python system path as explained hereafter.

The following has been taken from 


Initializing the Maya Environment in and for Python

Maya runs any Python commands in the userSetup.py file whenever it starts up. You can use this file to set up your working environment or execute commonly used Python commands such as importing the maya.cmds module.
The userSetup.py script is executed during the initialization and setup phase of Maya; therefore, only commands which set up your working environment and have no dependencies on Maya functionality can be successfully run in this script.
Note:
You can use maya.utils.executeDeferred() to delay code execution until after the Maya scene is initialized. For more information, see maya.utils.
  1. Create a file named userSetup.py in the following folder:
    • Windows: <drive>:\Documents and Settings\<username>\My Documents\maya\<Version>\scripts
    • Mac OS X: ~/Library/Preferences/Autodesk/maya/<version>/scripts
    • Linux: ~/maya/<version>/scripts
  2. In the userSetup.py file, type the commands you want Maya to run on start up; for example, import maya.cmds as mc.
    Note:
    Make sure you save the file with the right extension (.py).

Adding items to your Python path

To add items to your path in Python, do one of the following:
  1. Set PYTHONPATH in your Maya.env file, or in your environment before you run Maya
  2. Append to sys.path in your userSetup.py or other script once Maya is running.
Here is an example of appending sys.path
import sys sys.path.append( '/Users/jdoe/maya/Scripts' )
Note: userSetup.py must be located in the initial python path ( sys.path) in order to be run automatically at startup. The default Python path can be added to by setting the environment variable PYTHONPATH.

MEL and Python importing

If you have a MEL script in your path, you do not need to source it before accessing any single global procedure it contains with the same name. However, Python requires you to import a script explicitly before accessing any classes or functions it contains; for example:
# This will access the function "bar" in the file "foo.py"
import foo
foo.bar()

No hay comentarios:

Publicar un comentario