`
schi
  • 浏览: 200990 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

helloWorld.py

阅读更多
#!/usr/bin/env python
# -*- coding: UTF-8 -*-

#
# 描述: 
#     运行这个程序将会启动一个Maya独立的python程序
#
# 使用方法:
#
#       设置MAYA_LOCATION环境变量到你的Maya安装路径并在Linux(Mac)的shell中执行:
#
#       $MAYA_LOCATION/bin/mayapy helloWorld.py
#
#       注意:你必须使用Python可执行文件,才能正常工作。不同的平台它的路径都不一样。
#       win系统的是:
#       
#       $MAYA_LOCATION/bin/mayapy.exe helloWorld.py

# 导入相关模块
import maya.standalone
import maya.OpenMaya as OpenMaya

import sys

def main( argv=None ):
    try:
        # 尝试启动Maya独立的python程序
        maya.standalone.initialize( name='python' )
    except:
        # 如果无法启动,输出错误信息
        sys.stderr.write( "Failed in initialize standalone application" )
        raise
    
    # 输出Hello world
    sys.stderr.write( "Hello world! (script output)\n" )
    # 执行print命令来输出Hello world
    OpenMaya.MGlobal().executeCommand( "print \"Hello world! (command script output)\\n\"" )
        
if __name__ == "__main__":
    main()

你可以在maya安装目录下的devkit找到helloWorld.py。
在线版
http://download.autodesk.com/us/maya/2010help/API/hello_world_8py-example.html
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics