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. Invoke-WebRequest Invoke-RestMethod 乱码研究

    powershell Invoke-WebRequest Invoke-RestMethod 乱码 encoding sharset CharacterSet Invoke-WebRequest和In ...

  2. Python 初级项目:远程操控电脑(三)-极客学院

    http://www.jikexueyuan.com/course/2376_1.html

  3. MyJni

    package com.baidu.jnitest; import android.os.Bundle; import android.app.Activity; import android.vie ...

  4. sql 跨域

    1. 开通分布式查询权限 reconfigure reconfigure 2. 查询 ',NETACS.dbo.tb_car) a select * from opendatasource('SQLO ...

  5. 配置ConvenientBanner时出现的问题

    ConvenientBanner: compile 'com.bigkoo:convenientbanner:2.0.5' 找不到依赖库 classpath 'com.jfrog.bintray.gr ...

  6. 三部曲二(基本算法、动态规划、搜索)-1006-The Same Game

    The Same Game Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4585   Accepted: 1699 Des ...

  7. border-image(转载)

    本文转自:http://www.zhangxinxu.com/wordpress/2010/01/css3-border-image%E8%AF%A6%E8%A7%A3%E3%80%81%E5%BA% ...

  8. 7个你可能不认识的CSS单位:rem vh vw vmin vmax ex ch

    rem 我们首先介绍下和我们熟悉的很相似的货.em 被定义为相对于当前对象内文本的字体大小.炒个栗子,如果你给body小哥设置了font-size字体大小,那么body小哥的任何子元素的1em就是等于 ...

  9. VoxelGrid体素滤波器对点云进行下采样

    使用体素化网格方法实现下采样,即减少点的数量,减少点云数据,并同时保持点云的形状特征,在提高配准.曲面重建.形状识别等算法速度中非常实用. PCL实现的VoxelGrid类通过输入的点云数据创建一个三 ...

  10. vim文本编辑器

    一.vim相对于vi所做的提升 1.支持多级撤销(字母u, vi中只能撤销一部) 2.支持跨平台(unix为内核系统,windows也可以) 3.语法高亮 4.支持图形界面 二.vi编辑器的操作模式 ...