用python编写maya插件

1. python的安装

在Eclipse中安装pydev环境,pydev更新地址为:  http://pydev.org/updates

2. 配置python环境:

打开Eclipse菜单Window/Preferences,在PyDev中配置Python Interpreter的设置如下:

用python编写maya插件_第1张图片

注意要添加devkit\other\pymel\extras\completion\py目录。这样才有提示。

添加python代码:

import sys
import maya.OpenMaya as OpenMaya
import maya.OpenMayaMPx as OpenMayaMPx

kPluginCmdName = "spHelloWorld"

#command
class scriptedCommand(OpenMayaMPx.MPxCommand):
    def __init__(self):
        OpenMayaMPx.MPxCommand.__init__(self)
        
    #invoked when the command is run.
    def doIt(self, argList):
        print "hello World!"
        
#creator
def cmdCreator():
    return OpenMayaMPx.asMPxPtr(scriptedCommand())

#initialize the script plug-in
def initializePlugin(mobject):
    mplugin = OpenMayaMPx.MFnPlugin(mobject)
    try:
        mplugin.registerCommand(kPluginCmdName, cmdCreator)
    except:
        sys.stderr.write("Failed to register command: %s\n" % kPluginCmdName)
        raise
    
#uninitialize the script plug-in
def uninitializePlugin(mobject):
    mplugin = OpenMayaMPx.MFnPlugin(mobject)
    try:
        mplugin.deregisterCommand(kPluginCmdName)
    except:
        sys.stderr.write("Failed to unregister command: %s\n" % kPluginCmdName)
        

这个例子是官方的 Your First Maya Python Plug-in

还有更多例子,可以参考maya目录devkit下


参考文章:

1. Debugging Python in Maya with Eclipse/Pydev : http://around-the-corner.typepad.com/adn/2012/10/debugging-python-in-maya-with-eclipsepydev.html

2. Using Eclipse with Maya: A Quick Reference: http://techartninja.com/using-eclipse-with-maya-a-quick-reference/

3. Remote Maya Python Debugging in Eclipse: http://www.jason-parks.com/artoftech/?p=41

4. [pydev.org] Remote Debugger:  http://pydev.org/manual_adv_remote_debugger.html

5. Setting Up PyMEL Autocompletion in Eclipse: http://download.autodesk.com/global/docs/maya2012/ja_jp/PyMel/eclipse.html

6. How to Setup PyMEL Autocompletion in Eclipse: https://pymel.googlecode.com/svn/sphinx-docs/pymel_eclipse.html

你可能感兴趣的:(python,Maya)