六、通过插件如何创建自己的MEL command
1. MAYA API支持不同类型的plugin
(1)Command Plugin——扩充MEL命令
(2)Tool Commands——通过鼠标输出
(3)DG plugin——对场景添加新的操作
(4)Device Plugin——让其他的device链接到maya
2. register 命令:MFnPlugin
例子:
#include <stdio.h>
#include <maya/MString.h>
#include <maya/MArgList.h>
#include <maya/MFnPlugin.h>
#include <maya/MPxCommand.h>
#include <maya/MIOStream.h>
class hello : public MPxCommand
{
public:
MStatus doIt( const MArgList& args );
static void* creator();
}; MStatus hello::doIt( const MArgList& args ) {
cout << "Hello " << args.asString( ).asChar() << endl;
return MS::kSuccess;
} void* hello::creator() {
return new hello;
} MStatus initializePlugin( MObject obj ) {
MFnPlugin plugin( obj, "Autodesk", "1.0", "Any" );
plugin.registerCommand( "hello", hello::creator );
return MS::kSuccess;
} MStatus uninitializePlugin( MObject obj ) {
MFnPlugin plugin( obj );
plugin.deregisterCommand( "hello" );
return MS::kSuccess;
}
3. initializePlugin()
The initializePlugin() function can be defined as either a C or C++ function. If you do not define this function, the plug-in will not be loaded.
initializePlugin() contains the code to register any commands, tools, devices, and so on, defined by the plug-in with Maya.
For example, commands and tools are registered by instantiating an MFnPlugin function set to operate on the MObjectpassed in. This MObject contains Maya private information such as the name of the plug-in file and the directory it was loaded from.
Once constructed, the MFnPlugin function set is used to register the contents of the plug-in file.
4. MPxCommand:
proxy让我们可以在maya中构建新的object类型,可以集成新的功能到maya中。
A minimum of two methods must be defined. These are the doIt() method and the creator.
In this case the destructor is called immediately since the command cannot be undone. Maya treats a non-undoable command as an action that does not affect the scene in any way. This means that no information needs to be saved after the command executes, and when undoing and redoing commands, it does not need to be executed since it does not change anything.
The doIt() method is the only one that receives arguments. The undoIt()and redoIt() methods each take their data from internal data of the command itself.
In the final else-clause, the displayError() method, inherited from MPxCommand, outputs the message in the command window and in the command output window. Messages output with displayError() are prefixed with "Error:". Another option isdisplayWarning() which would prefix the message with "Warning:".
MStatus CommandExample::doIt( const MArgList& args)
//
// Description:
// implements the MEL CommandExample command.
//
// Arguments:
// args - the argument list that was passes to the command from MEL
//
// Return Value:
// MS::kSuccess - command succeeded
// MS::kFailure - command failed (returning this value will cause the
// MEL script that is being run to terminate unless the
// error is caught using a "catch" statement.
//
{
MStatus stat = MS::kSuccess;
//parse the arguments
for(int i=; i < args.length(); i ++){
if(MString("-p") == args.asString(i, &stat)
&& MS::kSuccess == stat){
double tmp = args.asDouble(++i, &stat);
if(MS::kSuccess == stat){
pitch = tmp;
}
}
else if(MString("-r") == args.asString(i, &stat)
&&MS::kSuccess == stat){
double tmp = args.asDouble(++i, &stat);
if(MS::kSuccess == stat)
radius = tmp;
}
else{
MString msg = "Invalid flag";
msg += args.asString(i);
displayError( msg );
return MS::kFailure;
}
} //get the first selected curve from the selection list
MSelectionList slist;
MGlobal::getActiveSelectionList( slist );
MItSelectionList list(slist, MFn::kNurbsCurve, &stat);
if(MS::kSuccess != stat){
displayError("could not create selection list iterator");
return stat;
}
if(list.isDone()){
displayError("no curve selected");
return MS::kFailure;
} MObject component;
list.getDagPath(fDagPath, component); return redoIt();
}
一旦所有需要的数据都get到了之后,就调用redoIt()函数。
The doIt() method could perform the necessary actions itself, but these actions are always identical to those performed by redoIt() so, having doIt() call redoIt() reduces code duplication.
Commands can also return results to MEL. This is done using the set of overloaded "setResult" and "appendToResult" methods inherited from MPxCommand.
Unless otherwise specified, all API methods use Maya internal units—cm and radians.
六、通过插件如何创建自己的MEL command的更多相关文章
- Maven3路程(六)用Maven创建Spring3 MVC项目
Maven3路程(六)用Maven创建Spring3 MVC项目 一. 环境 spring-framework-3.2.4.RELEASE jdk1.7.0_11 Maven3.0.5 ec ...
- cordova自定义插件的创建过程
最近学习了cordova插件,记录一下大概的过程,仅供参考. 前期的配置就不记录了网上好多. 在简书上从新写了一个更详细的cordova插件教程,有需要的可以点这里进去看看. 第一步 创建一个cord ...
- oracle入坑日记<六>自增列创建和清除(含序列和触发器的基础用法)
0 前言 用过 SQLserver 和 MySQL 的自增列(auto_increment),然而 Oracle 在建表设置列时却没有自增列. 查阅资料后发现 Oracle 的自增列需要手动编写. ...
- jQuery Accordion 插件用于创建折叠菜单
jQuery Accordion 插件用于创建折叠菜单.它通常与嵌套的列表.定义列表或嵌套的 div 一起使用.选项用于指定结构.激活的元素和定制的动画. 后期完善
- 从零开始编写属于我的CMS:(六)插件
二三四五还没写,先写六吧(有道友说想看看插件部分). 这里是一 从零开始编写属于我的CMS:(一)前言 一,首先预定义接口 新建类库,WangCms.PluginInterface 新建两个类,一个实 ...
- Chrome开发者工具不完全指南(六、插件篇)
本篇是Chrome开发者工具的结尾篇,最后为大家介绍几款功能强大的插件.在chrome商店里面有很多插件,没事建议大家去逛逛.不过需要FQ,所以诸位请自备神器.一.皮肤插件 首先是大家期盼已久,翘首以 ...
- 浅谈DevExpress<六>:为chart创建动态数据源
今天搞点稍微复杂些的东西,在列表中点击不同的行时,图表中显示和其数据关联的图,效果如下:
- IntelliJ IDEA安装scala插件并创建scala示例
1.http://blog.csdn.net/a2011480169/article/details/52712421 2.http://blog.csdn.net/stark_summer/arti ...
- 用laravel dingo api插件库创建api的一些心得笔记
用laravel创建api是很多大型项目正在使用的方法,一般他们都是用dingo api插件库来开发自己的api.以下是ytkah用dingo api的一些心得,有需要的朋友可以关注一下 1.安装 因 ...
随机推荐
- SQLSTATE[HY000] [2003] Cant connect to MySQL server
今天要连远程数据库,结果PHP报错 Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2003 ...
- C# List和String互相转换
List转字符串,用逗号隔开 List<string> list = new List<string>();list.Add("a");list.Add(& ...
- iOS学习之沙盒
1.iOS沙盒 iOS应用程序只能在为该改程序创建的文件系统中读取文件,不可以去其它地方访问,此区域被成为沙盒,所以所有的非代码文件都要保存在此,例如图像,图标,声音,映像,属性列表,文本文件等. 1 ...
- java SE 常用的排序算法
java程序员会用到的经典排序算法实现 常用的排序算法(以下代码包含的)有以下五类: A.插入排序(直接插入排序.希尔排序) B.交换排序(冒泡排序.快速排序) C.选择排序(直接选择排序.堆排序) ...
- 关于工伤事故索赔计算很好用的一款APP
关于工伤事故索赔计算很好用的一款APP.详细介绍工伤伤残等级评估 工伤计算器根据国家颁布<劳动能力鉴定 职工工伤与职业病致残等级>,通过关键字检索,快速评估工伤伤残等级. 软件说明: 1 ...
- C#数据结构
数据结构是相互之间存在一种或多种特定关系的数据元素的集合.在任何问题中,数据元素之间都不是孤立的,而是存在着一定的关系,这种关系称为结构(Structure).根据数据元素之间关系的不同特性,通常有 ...
- 学习笔记:HSB、HSL
转自知乎:http://www.zhihu.com/question/22077462 HSB 为 色相,饱和度,明度, HSL 为 色相,饱和度,亮度, HSV 为色相,饱和度,明度. HSB 和 ...
- IOS网络开发(一)
1 简易的聊天工具 1.1 问题 Socket的英文原义是孔或者插座的意思,通常也称作套接字,用于描述IP地址和端口,是一个通信链的句柄,本案例使用第三方Socket编程框架AsyncSocket框架 ...
- source insight shift+tab问题
之前用的好好的,shift+tab功能为向左缩进(即tab的相反功能),但是突然就有问题了:现象为只是光标向左移动,但文本不动. 解决方法: 1 使用快捷键f9 2 重新定义快捷键,把shift+ta ...
- mysql数据库 myisam数据存储引擎 表由于索引和数据导致的表损坏 的修复 和检查
一.mysqlcheck 进行表的检查和修复 1.检查mysqlisam存储引擎表的状态 #mysqlcheck -uuser -ppassword database table -c #检查单 ...