A note about the tool ** mayapy ** provided within Autodesk Maya. This is a continuation of the Maya part of this article
Python interpreter in Maya, Houdini, blender, Nuke http://qiita.com/it_ks/items/ae1d0ae01d831c2fc9ae
mayapy Maya version of python.exe. It's called python.exe that can summon Maya functions.
Roughly speaking, if you have Maya installed You don't have to install Python separately (in a win environment) to use this.
C:\Program Files\Autodesk¥Maya{ver}\bin\mayapy.exe
It is in the same order as Maya itself (maya.exe).
Double-click to open a black window and use it as a normal Python interpreter.
~~ I will look it up later and write it ~~ ([Addition] I told you in the comments!)
/Applications/Autodesk/maya{ver}/Maya.app/Contents/bin/mayapy
Mayapy 2016 built-in mayapy.exe The version as Python is ** 2.7.6 **.
The version is displayed when mayapy.exe is started, but if you want to get it in your Python code
version confirmation
import sys
sys.version
sys.version_info
Around.
init There is a module for using Maya features, Must be initialized after import. I'm touching that area lightly here
http://qiita.com/it_ks/items/ae1d0ae01d831c2fc9ae#%E3%83%A2%E3%82%B8%E3%83%A5%E3%83%BC%E3%83%AB
You can give a script at startup to automatically process it, or specify options to change the behavior. When checking what options are available
"C:\Program Files\Autodesk\Maya2016\bin\mayapy.exe" -h
Add -h
or --help
.
Then it looks like this (▼)
mayapy-help
usage: C:\Program Files\Autodesk\Maya2016\bin\mayapy.exe [option] ... [-c cmd | -m mod | file | -] [arg] ...
Options and arguments (and corresponding environment variables):
-B : don't write .py[co] files on import; also PYTHONDONTWRITEBYTECODE=x
-c cmd : program passed in as string (terminates option list)
-d : debug output from parser; also PYTHONDEBUG=x
-E : ignore PYTHON* environment variables (such as PYTHONPATH)
-h : print this help message and exit (also --help)
-i : inspect interactively after running script; forces a prompt even
if stdin does not appear to be a terminal; also PYTHONINSPECT=x
-m mod : run library module as a script (terminates option list)
-O : optimize generated bytecode slightly; also PYTHONOPTIMIZE=x
-OO : remove doc-strings in addition to the -O optimizations
-R : use a pseudo-random salt to make hash() values of various types be
unpredictable between separate invocations of the interpreter, as
a defense against denial-of-service attacks
-Q arg : division options: -Qold (default), -Qwarn, -Qwarnall, -Qnew
-s : don't add user site directory to sys.path; also PYTHONNOUSERSITE
-S : don't imply 'import site' on initialization
-t : issue warnings about inconsistent tab usage (-tt: issue errors)
-u : unbuffered binary stdout and stderr; also PYTHONUNBUFFERED=x
see man page for details on internal buffering relating to '-u'
-v : verbose (trace import statements); also PYTHONVERBOSE=x
can be supplied multiple times to increase verbosity
-V : print the Python version number and exit (also --version)
-W arg : warning control; arg is action:message:category:module:lineno
also PYTHONWARNINGS=arg
-x : skip first line of source, allowing use of non-Unix forms of #!cmd
-3 : warn about Python 3.x incompatibilities that 2to3 cannot trivially fix
file : program read from script file
- : program read from stdin (default; interactive mode if a tty)
arg ...: arguments passed to program in sys.argv[1:]
Other environment variables:
PYTHONSTARTUP: file executed on interactive startup (no default)
PYTHONPATH : ';'-separated list of directories prefixed to the
default module search path. The result is sys.path.
PYTHONHOME : alternate <prefix> directory (or <prefix>;<exec_prefix>).
The default module search path uses <prefix>\lib.
PYTHONCASEOK : ignore case in 'import' statements (Windows).
PYTHONIOENCODING: Encoding[:errors] used for stdin/stdout/stderr.
PYTHONHASHSEED: if this variable is set to 'random', the effect is the same
as specifying the -R option: a random value is used to seed the hashes of
str, bytes and datetime objects. It can also be set to an integer
in the range [0,4294967295] to get hash values with a predictable seed.
What seems to be particularly important
is.
-c
-c cmd : program passed in as string (terminates option list)
Write a Python command following the -c option.
Use this option at the end of the options list (this option exits the options list)
-m
-m mod : run library module as a script (terminates option list)
Run the module as a script.
This option, like -c, is used at the end of the options list
file
file : program read from script file
Give mayapy the file you want it to run (the .py file that contains the Python code).
For some reason, I think this is the one I use most often.
arg
arg ...: arguments passed to program in sys.argv[1:]
Items written after the option are stored after the second item of sys.argv.
For example
"C:\Program Files\Autodesk\Maya2016\bin\mayapy.exe" -c "import sys;print sys.argv" test 1234 %date%
If you do this
['-c', 'test', '1234', '2015/12/29']
It will be printed like this.
Even if it is not enclosed in "~", it is treated as a character string, and numbers are also character strings. Variables from% to% can also be used.
After that, the verification was completed and now it is described as "Win10 support in Maya 2016 or later" [** Support for Windows 10 and .NET 4.6 for Autodesk products **](https://knowledge.autodesk.com/en/support/autocad/learn-explore/caas/sfdcarticles/sfdcarticles/JPN/Windows-10- support-for-Autodesk-products.html)
Use Python from an external interpreter http://help.autodesk.com/view/MAYAUL/2016/JPN/?guid=GUID-83799297-C629-48A8-BCE4-061D3F275215
How to process multiple scene files at once http://www.dfx.co.jp/dftalk/?p=17829
Maya Python help usage options and environment variables http://www.cghelpline.com/article/maya-python-help-usage-options-and-environment-variables/133
Python command line options http://docs.python.jp/2/using/cmdline.html
Recommended Posts