[Python] Open Maya File from Command Line


#1

Say I have a python shell that knows absolutely 0% about Maya and I run

import sys
  
  sys.path.append("path/to/maya2016/pythonX.X/site-packages")
  
  import maya.cmds as cmds
  
  cmds.file("some/file/path/foo.ma, o=True)
  

that should open a maya file but in linux, I get the following error:
AttributeError: ‘module’ object has no attribute ‘file’

Running the following:

import inspect
  inspect.getmembers(cmds, inspect.isfunction)

returns [], which means that the module imported with no methods (aka, I did it incorrectly or something else is amiss)

I get the same problem in windows. I navigated to the actual maya/cmds folder and it only has an empty init.py inside of it so my question is how does Maya actually load its own modules and how can I take advantage of that so I can properly import maya.cmds from outside of the Maya GUI?


#2

You can run the maya.cmds only from within a maya environment, either by starting a mayabatch session or by running mayapy. Have a look at:

http://help.autodesk.com/view/MAYAUL/2016/ENU//?guid=__files_Maya_Python_API_Using_the_Maya_Python_API_htm


#3

Hi haggi, I took some time to write an application using maya.standalone but I’m running into the following error on Linux:

ImportError: /usr/autodesk/maya/lib/python2.7/site-packages/maya/_OpenMaya.so: undefined symbol: _ZN6MPointC1ERK11MFloatPoint

Any idea what could be the problem? I’m executing from mayapy on the helloworld script posted under the link you sent