helloWorldCmd.py

这个helloWorldCmd.py和helloWorld.py不同,后者是通过maya.standalone来运行的,而前者是以插件的形式来使用的。
使用方法:
将helloWorldCmd.py放到
win
C:\Documents and Settings\你的用户名\My Documents\maya\plug-ins

mac
/Users/你的用户名/Library/Preferences/Autodesk/maya/plug-ins

如果不存在plug-ins文件夹,就创建一个
在脚本编辑器中执行:
loadPlugin helloWorldCmd.py;
spHelloWorld;


import maya.cmds as cmds
cmds.loadPlugin("helloWorldCmd.py")
cmds.spHelloWorld()


helloWorldCmd.py
#!/usr/bin/env python
# -*- coding: UTF-8 -*-

'''
Created on Oct 25, 2009

@author: schi
'''
# 使用方法:
# Mel:
# loadPlugin helloWorldCmd.py;
# spHelloWorld;
#
# ---------------------------------------
#
# python:
# import maya.cmds as cmds
# cmds.loadPlugin("helloWorldCmd.py")
# cmds.spHelloWorld()

# 导入相关模块
import sys
import maya.OpenMaya as om
import maya.OpenMayaMPx as ompx

# 定义命令的名称
kPluginCmdName = 'spHelloWorld'

# 命令
class SpHelloWorld( ompx.MPxCommand ):

def __init__( self ):
# 你可以像官方一样使用未绑定的方法,ompx.MPxCommand.__init__(self)
# 我更倾向于super方法
super( SpHelloWorld, self ).__init__()

# 执行spHelloWorld时会调用这个方法
def doIt( self, argList ):
# 如果你对Hello World很反感,可以改成自己的代码
print "Hello World!"

# Creator用于创建命令的一个实例
def cmdCreator():
return ompx.asMpxPtr( SpHelloWorld() )

# 注册插件
def initializePlugin( mobject ):
mplugin = ompx.MFnPlugin( mobject )
try:
mplugin.registerCommand( kPluginCmdName, cmdCreator )
except:
sys.stderr.write( '插件 %s 注册失败\n' % kPluginCmdName )
raise

# 注销插件
def uninitializePlugin( mobject ):
mplugin = ompx.MFnPlugin( mobject )
try:
mplugin.deregisterCommand( kPluginCmdName )
except:
sys.stderr.write( '插件 %s 注销失败\n' % kPluginCmdName )
raise

你可以在maya安装目录下的devkit/plug-ins/scripted找到helloWorldCmd.py。
在线版
[url]http://download.autodesk.com/us/maya/2010help/API/hello_world_cmd_8py-example.html[/url]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值