You can run a commandline-only maya using mayapy
, the python interpreter that ships with Maya. You can do almost everything in mayapy that you can do in a regular maya script listener, although commands that manipulate GUI objects and some kinds of plugins may not work.
Mayapy is typically located in your maya install folder (something like C:/Program Files/Autodesk/Maya2019/bin/mayapy.exe
on windows). From a commandline you'd do something like this:
>>> /c/"Program Files"/Autodesk/Maya2019/bin/mayapy.exe
Python 2.7.11 (default, Jul 1 2016, 02:08:48) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import maya.standalone
>>> maya.standalone.initialize()
>>> import maya.cmds as cmds
>>> cmds.polyCube()
[u'pCube1', u'polyCube1']
>>> cmds.xform('pCube1', t = (1,2,3))
>>> print cmds.getAttr('pCube1.t')
[(1.0, 2.0, 3.0)]
The key bit is maya.standalone.initialize()
, which activates all of the maya functionality.
If you don't need to interact with the job -- if i'ts just running a script without opening the full gui app -- just write a python script which starts by importing maya.standalone and initializing it. Then you just pass it straight to mayapy:
/c/"Program Files"/Autodesk/Maya2019/bin/mayapy.exe myscript.py
that will open mayapy and run your script. Great for automating simple offline tasks.