I'm trying to set up the Eclipse IDE to recognize the maya.cmds module, an all modules associated with the maya module. The following code are tests run in Eclipse, and Maya's script editor.
import maya
print 'maya:\n', dir(maya)
from maya import cmds
print 'cmds:\n', len(dir(cmds)) # too many to print
print 'sphere: ', cmds.sphere
In Maya's script editor the code results in
maya:
['OpenMaya', '_OpenMaya', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__', 'app', 'cmds', 'mel', 'standalone', 'stringTable', 'utils']
cmds:
3190
sphere: <built-in method sphere of module object at 0x0000000019F0EEE8>
In Eclipse the code results in
maya:
['__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__']
cmds:
6
sphere:
Traceback (most recent call last):
AttributeError: 'module' object has no attribute 'sphere'
I've done开发者_如何学C a lot of searching, on the google group "python inside maya", and web searches. The best I've found was the following link, however this did not solve my issue at all, and in the end gave the same result. http://www.luma-pictures.com/tools/pymel/docs/1.0/eclipse.html
I've read that I should be setting my environment paths in Eclipse, rather than my machine, and I've also read the opposite opinion. What environment vars should I set, to where, and in Eclipse, Windows, or both?
The solution is to import maya.standalone and initialize it. This gives you access to the maya packages and modules therein.
import maya.standalone
maya.standalone.initialize()
import maya
print 'maya:\n', dir(maya)
from maya import cmds
print 'cmds:\n', len(dir(cmds)) # too many to print
print 'sphere: ', cmds.sphere
output:
maya:
['__builtins__', '__doc__', '__file__', '__name__', '__package__',
'__path__', 'app', 'cmds', 'mel', 'standalone', 'stringTable', 'test', 'utils']
cmds:
2945
sphere: <built-in method sphere of module object at 0xf33948>
If you want you can setup eclipse to run (debug) maya directly on it (using standalone, of course).
If you go in python interpreters you can add a mayapy interpreter.
Press new
, write the new that you want :D,
interpreter executable will be your maya path ) ..\bin\mayapi.exe
(eg: D:\Program Files\Autodesk\Maya2013\bin\mayapi.exe
)
Include all the the modules that you think you need, and done. now you can use maya interpreter inside eclipse, this it means that with maya standalone, you can run your script as well ( I like to use this way if I need to do a recursive task o similar ;) ).
精彩评论