Eclipse environment for Maya's python modules

孤者浪人 提交于 2019-12-12 08:13:35

问题


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


回答1:


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>



回答2:


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 ;) ).



来源:https://stackoverflow.com/questions/4841190/eclipse-environment-for-mayas-python-modules

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!