if you are trying to get access to maya.cmds from a python script
which is called from an external interpreter (outside maya) you should
use mayapy, found in the maya bin directory. i assume that you are
already doing this or else the maya standalone calls would not work.
the problem is that when you start maya this way, it does not parse
your Maya.env. pymel makes this much easier: when it is imported in
batch mode, it parses your Maya.env and sets up your environment
variables as they would be in GUI mode. it also handles importing and
intializing maya.standalone -- you just import pymel as you normally
would.
in case anyone else is curious, you can ensure that your script is
using mayapy by:
1) calling it with mayapy:
/usr/autodesk/maya2008/bin/mayapy myScript.py
2) adding a mayapy directive to the first line of your script:
#!/usr/autodesk/maya2008/bin/mayapy
here's a little mayapy demystification. mayapy is just a simple shell
script. this is the contents of mayapy on osx with explanations of
each code segment:
#!/bin/sh
#get the current path where the mayapy script resides
path=`dirname $0`
# set python to use maya's internal copy.
pythonhome=$path/../Frameworks/Python.framework/Versions/Current
export PYTHONHOME=$pythonhome
# setup environment variables necessary for finding frameworks and
libraries needed by maya's modules
export DYLD_LIBRARY_PATH=$path/../MacOS:$DYLD_LIBRARY_PATH
export DYLD_FRAMEWORK_PATH=$path/../Frameworks:$DYLD_FRAMEWORK_PATH
# set maya's location
export MAYA_LOCATION=$path/..
# execute maya's python interpreter
exec $pythonhome/Resources/Python.app/Contents/MacOS/Python "$@"
now python is ready to use maya's modules without having maya open.
-chad
On Apr 25, 10:00 am, "Chris Trimble" <
tri...@gmail.com> wrote:
> Try:
>
> * When your python script launches, extend os.environ with what you need
> (MAYA_SCRIPT_PATH, MAYA_PLUG_IN_PATH, etc). Then launch Mayabatch with the
> subprocess module and hand in this environment. This is what we do because
> it offers the most flexibility -- no user has Maya.env set anywhere, nor do
> they have permanent environment variables set for Windows. Everything is
> set up based on what script they use to launch Maya, so a user can change
> settings/projects easily.
>
> * I haven't used standalone very much, but in the code below if all you need
> is to set your PYTHONPATH, just import sys and append to sys.path. Once
> you're in Maya standalone, I imagine you could use setenv to set up the rest
> of the variables you need as well.
>
> HTH,
> Chris
>
> 2008/4/25 stanislav.glazov <
stanislav.gla...@googlemail.com>: