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. excel列递增方法技巧

    最近处理世界买家网100多万的数据,需要用到excel来对数据进行处理,其中有一项是对数据做一个排序,以方便数据导入时来对应唯一的id编号,之前都是 几万,最多也是30来万的数据,所以列递增就直接用鼠 ...

  2. Volley框架的使用

    所谓Volley,它是2013年Google I/O上发布的一款网络框架,基于Android平台,能使网络通信更快,更简单,更健全. 它的优点:(1)默认Android2.3及以上基于HttpURLC ...

  3. idea中如何配置tomcat

    这几天想通过JDBC驱动使用MySQL数据库,但老是运行不成功,但是写成java就没有问题,于是想到是不是服务器没配置好 idea中配置tomcat的步骤如下 1:File->Settings. ...

  4. Java/javaEE/web/jsp/网站编程环境配置及其软件下载和网站路径

    Java/javaEE/web/jsp/网站编程环境配置及其软件下载和网站路径 (2015/07/08更新) JDK下载地址(JDK官网下载地址) 下载地址为:http://www.oracle.co ...

  5. 【LeetCode OJ】Flatten Binary Tree to Linked List

    Problem Link: http://oj.leetcode.com/problems/flatten-binary-tree-to-linked-list/ The problem is ask ...

  6. 从零开始学习Node.js例子七 发送HTTP客户端请求并显示响应结果

    wget.js:发送HTTP客户端请求并显示响应的各种结果 options对象描述了将要发出的请求.data事件在数据到达时被触发,error事件在发生错误时被触发.HTTP请求中的数据格式通过MIM ...

  7. PHP正则表达式的快速学习方法

    1.入门简介 简单的说,正则表达式是一种可以用于模式匹配和替换的强有力的工具.我们可以在几乎所有的基于UNIX系统的工具中找到正则表达式的身影,例如,vi编辑器,Perl或PHP脚本语言,以及awk或 ...

  8. 12-1 mysql的增删改减

    增加数据:insert into 表名 values('','');insert into 表名(列名) values('');注意:1.如果添加 得数据是字符串,需要加'',其他类型不要加. 2.添 ...

  9. Android FM模块学习之四源码分析(3)

    接着看FM模块的其他几个次要的类的源码.这样来看FM上层的东西不是太多. 请看android\vendor\qcom\opensource\fm\fmapp2\src\com\caf\fmradio\ ...

  10. Python 决策树的构造

    上一节我们学习knn,kNN的最大缺点就是无法给出数据的内在含义,而使用决策树处理分类问题,优势就在于数据形式非常容易理解. 决策树的算法有很多,有CART.ID3和C4.5等,其中ID3和C4.5都 ...