六、通过插件如何创建自己的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.安装 因 ...
随机推荐
- powershell中的两只爬虫
--------------------序-------------------- (PowerShell中的)两只爬虫,两只爬虫,跑地快,爬网页不赖~~~ 一只基于com版的ie,一只基于.net中 ...
- fopen和fopen_s用法的比较 【zz】
在定义FILE * fp 之后,fopen的用法是: fp = fopen(filename,"w").而对于fopen_s来说,还得定义另外一个变量errno_t err,然后e ...
- HDU 4123 (2011 Asia FZU contest)(树形DP + 维护最长子序列)(bfs + 尺取法)
题意:告诉一张带权图,不存在环,存下每个点能够到的最大的距离,就是一个长度为n的序列,然后求出最大值-最小值不大于Q的最长子序列的长度. 做法1:两步,第一步是根据图计算出这个序列,大姐头用了树形DP ...
- SqlServer性能优化 手工性能收集动态管理视图(三)
动态管理视图: 具体的实例语句: --关于语句执行的基本情况 select * from sys.dm_exec_query_stats --动态管理函数 需要提供参数 select top 1 ...
- As 和 Is的区别
首先来说说As是干什么的: 代码: void OnMouseEnter(object sender, MouseEventArgs e){ Ellipse ell = sender as Ellips ...
- Makefile 开发环境全能管家
变量的应用: CC=gcc RM=rm EXE=main.exe OBJS=目标 伪目标的应用: .PHONY:clean 自动变量的应用: $@:表示一个规则的目标 $^:表示的是规则中的所有的先决 ...
- 《JavaScript模式》第4章 函数
@by Ruth92(转载请注明出处) 第4章:函数 一.JavaScript 中函数的两个重要特征 函数是第一类对象,可以作为带有属性和方法的值以及参数进行传递: 函数提供了局部作用域,而其他大括号 ...
- TestDisk 恢复rm -rf 的文件
Linux操作系统下使用TestDisk恢复已删除的文件或目录 原创作者:szyzln/2015.10.16 转载需注明原始出处! 说明: testdisk和photorec是著名的恢复数据,而绝 ...
- input file上传文件扩展名限制
方法一(不推荐使用):用jS获获取扩展名进行验证: <script type="text/javascript" charset="utf-8"> ...
- 怎样用JS获取ASP.NET服务器控件的客户端ID
虽然简单,不过曾经困扰多时,还是记录一下吧. 来源:http://mou518.blog.163.com/blog/static/1756052222010111434428828/ 因为经常服务器控 ...