0

How can I make changes in Maya file like making layers and saving it or saving it as without opening Maya application . I tried doing with pycharm and changing its settings path till mayapy but couldn't succed . I am not clear about this topic and searched alot over internet but some or other problem arises. Can someone please explain me or tell me if there is any tutorial in depth for this .

Thanks in advance

Kuber
  • 11
  • 1
  • 2

1 Answers1

2

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.

theodox
  • 12,028
  • 3
  • 23
  • 36
  • @PeterWood Thanks a lot these methods worked , I even have loaded Arnold module in my script to make changes in render global , but again the default render options were working while default Arnold options and driver gave an error as module not found . – Kuber Oct 24 '18 at 02:21
  • See if [this](https://docs.arnoldrenderer.com/display/arnsupp/2014/06/10/Loading+mtoa+in+mayapy) helps – theodox Oct 24 '18 at 19:10
  • I realised the mistake . I made Arnold plugin to work but it wasnt working because it doesnt creates its default nodes by default I was needed to create it manually as without GUI we needs to mention everything . Thanks friend for taking some time for me . :) – Kuber Oct 25 '18 at 20:00
  • You might want to mark the answer as accepted then so anybody who comes here via googling knows that this general approach works – theodox Oct 25 '18 at 20:35