mayapy --Python in Maya

What is this?

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.

place

Location in win

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. mayapy_boot.png

Location on OS X

~~ 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

version

Mayapy 2016 built-in mayapy.exe The version as Python is ** 2.7.6 **.

Verification

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

option

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.


Remarks

environment

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)

reference

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

mayapy --Python in Maya
Quadtree in Python --2
CURL in python
Metaprogramming in Python
Python 3.3 in Anaconda
Geocoding in python
SendKeys in Python
Meta-analysis in Python
Unittest in python
Epoch in Python
Discord in Python
Sudoku in Python
DCI in Python
quicksort in python
nCr in python
N-Gram in Python
Programming in python
Plink in Python
Constant in python
Lifegame in Python.
FizzBuzz in Python
Sqlite in python
StepAIC in Python
N-gram in python
LINE-Bot [0] in Python
Csv in python
Disassemble in Python
Reflection in Python
Constant in python
nCr in Python.
format in python
Scons in Python3
Puyo Puyo in python
python in virtualenv
PPAP in Python
Quad-tree in Python
Reflection in Python
Chemistry in Python
Hashable in python
DirectLiNGAM in Python
LiNGAM in Python
Flatten in python
flatten in python
Python interpreter in Maya, Houdini, blender, Nuke
Use pathlib in Maya (Python 2.7) for upcoming Python 3.7
Sorted list in Python
Daily AtCoder # 36 in Python
Clustering text in Python
Daily AtCoder # 2 in Python
Implement Enigma in python
Daily AtCoder # 32 in Python
Daily AtCoder # 6 in Python
Edit fonts in Python
Singleton pattern in Python
File operations in Python
Read DXF in python
Daily AtCoder # 53 in Python
Key input in Python
Use config.ini in Python
Daily AtCoder # 33 in Python
Solve ABC168D in Python