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的更多相关文章

  1. Maven3路程(六)用Maven创建Spring3 MVC项目

    Maven3路程(六)用Maven创建Spring3 MVC项目 一.      环境 spring-framework-3.2.4.RELEASE jdk1.7.0_11 Maven3.0.5 ec ...

  2. cordova自定义插件的创建过程

    最近学习了cordova插件,记录一下大概的过程,仅供参考. 前期的配置就不记录了网上好多. 在简书上从新写了一个更详细的cordova插件教程,有需要的可以点这里进去看看. 第一步 创建一个cord ...

  3. oracle入坑日记<六>自增列创建和清除(含序列和触发器的基础用法)

    0   前言 用过 SQLserver 和 MySQL 的自增列(auto_increment),然而 Oracle 在建表设置列时却没有自增列. 查阅资料后发现 Oracle 的自增列需要手动编写. ...

  4. jQuery Accordion 插件用于创建折叠菜单

    jQuery Accordion 插件用于创建折叠菜单.它通常与嵌套的列表.定义列表或嵌套的 div 一起使用.选项用于指定结构.激活的元素和定制的动画. 后期完善

  5. 从零开始编写属于我的CMS:(六)插件

    二三四五还没写,先写六吧(有道友说想看看插件部分). 这里是一 从零开始编写属于我的CMS:(一)前言 一,首先预定义接口 新建类库,WangCms.PluginInterface 新建两个类,一个实 ...

  6. Chrome开发者工具不完全指南(六、插件篇)

    本篇是Chrome开发者工具的结尾篇,最后为大家介绍几款功能强大的插件.在chrome商店里面有很多插件,没事建议大家去逛逛.不过需要FQ,所以诸位请自备神器.一.皮肤插件 首先是大家期盼已久,翘首以 ...

  7. 浅谈DevExpress<六>:为chart创建动态数据源

    今天搞点稍微复杂些的东西,在列表中点击不同的行时,图表中显示和其数据关联的图,效果如下:

  8. IntelliJ IDEA安装scala插件并创建scala示例

    1.http://blog.csdn.net/a2011480169/article/details/52712421 2.http://blog.csdn.net/stark_summer/arti ...

  9. 用laravel dingo api插件库创建api的一些心得笔记

    用laravel创建api是很多大型项目正在使用的方法,一般他们都是用dingo api插件库来开发自己的api.以下是ytkah用dingo api的一些心得,有需要的朋友可以关注一下 1.安装 因 ...

随机推荐

  1. HttpURLConnection网络请求

    //创建访问的方法 public String Check_json(){ //创建一个结果字符串 String result=""; //拼接字符串 StringBuffer s ...

  2. 2014年5月份第1周51Aspx源码发布详情

    郑州某高校学生考评系统源码  2014-5-5 [VS2008]功能介绍:   1.用户角色有部主任.教师.学生等.   2.可添加班级考评项目.学生考评项目.   3.可指定学生对班级.学生某考评项 ...

  3. SQL Server 2005 控制用户权限访问表

    转自:http://www.cnblogs.com/gaizai/archive/2011/07/14/2106617.html 一.需求 在管理数据库过程中,我们经常需要控制某个用户访问数据库的权限 ...

  4. Modbus工业协议在Android中的应用

    现在工业信息画发展,很多工厂都需要做信息化展示,通常都是利用Android一体机来进行展示和交互. Modbus协议是全球第一个用于工业现场的总线协议,与外设交互可以采用串口通信,tcp等方式:通常在 ...

  5. 使用PHP处理文本小技巧

    PHP的Cli模式使用:http://www.php.net/manual/zh/features.commandline.php PHP命令行部分参数:-B     在处理 stdin 之前先执行 ...

  6. C语言处理xml文件的库

    读取和设置xml配置文件是最常用的操作,试用了几个C++的XML解析器,个人感觉TinyXML是使用起来最舒服的,因为它的API接口和Java的十分类似,面向对象性很好. TinyXML是一个开源的解 ...

  7. 不同vlan之间的相互访问

    拓扑图: 用到的命令: 给端口的vlan <sw1>用户模式 切换到系统模式 system-view 交换机名称 sysname swj1 创建vlan 3 端口模式选择int g0/0/ ...

  8. Qt资源下载、安装、配置

    (一)资源下载: 硕士毕业论文要做一个仿真平台,在linux环境下利用Qt开发. 自己有一定的c/c++基础,Qt是零基础接触.所以,经过一番查找,发现youtube一个外国友人Bryan从零开始教Q ...

  9. Pylot压力测试(linux)

    Pylot需要python2.5以上的版本,打开以后选择对应你的系统的版本,下载好之后双击安装. centOS5.5 系统版本python版本是2.4.3,所以要下载个2.5以上的. 1.下载Pyth ...

  10. 计算纯文本情况下RichTextBox实际高度的正确方法(.NET)

    2016-07-17重大更新           其实有更好.更系统的方法,也是最近才发现的,分享给大家!! /// <summary> /// /// </summary> ...