十三、File Translator怎么写
---恢复内容开始---
1. File Translator可以将信息从maya中导入和导出。
2. 创建一个file translator需要从MPxFileTranslator继承。
3. 函数介绍:
(1)::canBeOpened()方法决定了file translator是否可以打开文件,如果只是一个importer那么就return flase,反之。
(2)importer:必须包含::haveReadMethod(), ::reader().
(3)exporter: 必须包含::haveWriteMethod(), ::writer().
4.设置translator允许访问所有的MEL命令: 在MFnPlugin::registerTranslator()函数中将requireFullMel参数值设置成true.
5. 例子, 一个polygon的exporter:
class polyExporter:public MPxFileTranslator
{
public:
polyExporter();
virtual ~polyExporter();
virtual MStatus writer (const MFileObject& file,
const MString& optionsString, MPxFileTranslator::FileAccessMode mode);
virtual bool haveWriteMethod () const;
virtual bool haveReadMethod () const;
virtual bool canBeOpened () const;
virtual MString defaultExtension () const = ;
protected:
virtual bool isVisible(MFnDagNode& fnDag, MStatus& status);
virtual MStatus exportAll(ostream& os);
virtual MStatus exportSelection(ostream& os);
virtual void writeHeader(ostream& os);
virtual void writeFooter(ostream& os);
virtual MStatus processPolyMesh(const MDagPath dagPath, ostream& os);
virtual polyWriter* createPolyWriter(const MDagPath dagPath, MStatus& status) = ;
};
6. MFnPlugin::registerFileTranslator()函数:
有6个参数,最后三个是可选的,
status = plugin.registerFileTranslator("RawText", "", polyRawExporter::creator, "", "option1=1", true);
RawText: is a name;
option1=1: default value for the option box for the translator;
true: means that you can use MGlobal::executeCommand() method in translator.
7. Reader:
如果要用reader()方法读取文件,那么haveReadMethod()方法要返回true
reader()方法读取文件的每一行,如果读取失败返回MS::kFailture
MStatus LepTranslator::reader ( const MFileObject& file,
const MString& options, MPxFileTranslator::FileAccessMode mode)
{ const MString fname = file.fullName(); MStatus rval(MS::kSuccess);
const int maxLineSize = ;
char buf[maxLineSize];
ifstream inputfile(fname.asChar(), ios::in);
if (!inputfile) {
// open failed
cerr << fname << ": could not be opened for reading\n";
return MS::kFailure;
}
if (!inputfile.getline (buf, maxLineSize)) {
cerr << "file " << fname << " contained no lines ... aborting\n";
return MS::kFailure;
}
//the first line has the magic chars.
if ( != strncmp(buf, magic.asChar(), magic.length())) {
cerr << "first line of file " << fname;
cerr << " did not contain " << magic.asChar() << " ... aborting\n";
return MS::kFailure;
}
while (inputfile.getline (buf, maxLineSize)) {
//processing each line of the file
MString cmdString;
cmdString.set(buf);
if (!MGlobal::executeCommand(cmdString))
rval = MS::kFailure;
}
inputfile.close();
return rval;
}
8. writer()方法, 类似reader()方法:
通过script editor来提供message,在这个例子中只提供export all 和export selection选项,其他的选项将输出failure message.
MStatus polyExporter::writer(const MFileObject& file,
const MString& /*options*/, MPxFileTranslator::FileAccessMode mode)
{ const MString fileName = file.fullName();
ofstream newFile(fileName.asChar(), ios::out);
if (!newFile) {
MGlobal::displayError(fileName + ": could not be opened for reading");
return MS::kFailure;
}
newFile.setf(ios::unitbuf);
writeHeader(newFile);
if (MPxFileTranslator::kExportAccessMode == mode) {
if (MStatus::kFailure == exportAll(newFile)) {
return MStatus::kFailure;
}
}
else if (MPxFileTranslator::kExportActiveAccessMode == mode) {
if (MStatus::kFailure == exportSelection(newFile)) {
return MStatus::kFailure;
}
}
else {
return MStatus::kFailure;
}
writeFooter(newFile);
newFile.flush();
newFile.close();
MGlobal::displayInfo("Export to " + fileName + " successful!");
return MS::kSuccess;
}
9. file extention:
MString polyRawExporter::defaultExtension () const
{
return MString("raw");
}
10. file access mode:
十三、File Translator怎么写的更多相关文章
- 第二十三个知识点:写一个实现蒙哥马利算法的C程序
第二十三个知识点:写一个实现蒙哥马利算法的C程序 这次博客我将通过对蒙哥马利算法的一个实际的实现,来补充我们上周蒙哥马利算法的理论方面.这个用C语言实现的蒙哥马利算法,是为一个位数为64的计算机编写的 ...
- 黑马程序员——File笔记读,写,复制
#region ReadAllBytes byte[] buffer = File.ReadAllBytes(@"C:\Users\dell\Desktop\新建文件夹.txt") ...
- Java之IO(十三)File、Filter、Piped、String和InputStreamReader与OutputStreamWriter
转载请注明原出处:http://www.cnblogs.com/lighten/p/7264196.html 1.前言 断更一段时间,计划果然赶不上变化(还是太懒...).这次一次性将剩余的5组字符流 ...
- 安卓开发笔记(三十三):Android仿写微信发现
首先我们来看看仿写之后的效果: 看到是这个界面我们首先应该思考这些按钮是怎么做出来的?有了一个整体的思路之后才知道该怎么办.最开始我想的就直接利用button控件上面直接加上png的图片就可以形成一个 ...
- python【第十三篇】可以写一个堡垒机了
前景介绍 到目前为止,很多公司对堡垒机依然不太感冒,其实是没有充分认识到堡垒机在IT管理中的重要作用的,很多人觉得,堡垒机就是跳板机,其实这个认识是不全面的,跳板功能只是堡垒机所具备的功能属性中的其中 ...
- File相关的读取和写入以及复制
import java.io.BufferedReader;import java.io.BufferedWriter;import java.io.File;import java.io.FileI ...
- 黑马程序员——【Java基础】——File类、Properties集合、IO包中的其他类
---------- android培训.java培训.期待与您交流! ---------- 一.File类 (一)概述 1.File类:文件和目录路径名的抽象表现形式 2.作用: (1)用来将文件或 ...
- input file样式修改,图片预览删除功能
本篇对input file进行了修改,改成自己需要的样式,类似验证身份上传身份证图片的功能. 效果图如下: 这里主要展示上传预览图片功能,对于删除功能的html及css写的比较粗糙,对于想要精细表现这 ...
- GO开发:用go写个日志监控系统
日志收集系统架构 1.项目背景 a. 每个系统都有日志,当系统出现问题时,需要通过日志解决问题 b. 当系统机器比较少时,登陆到服务器上查看即可满足 c. 当系统机器规模巨大,登陆到机器上查看几乎不现 ...
随机推荐
- Oracle执行时间与sql格式
今天碰到一个很奇怪的问题,直接在eclipse中将sql拷出,然后直接粘贴复制在数据库中就会执行的非常慢,但是在利用plsql对sql语句进行格式整理之后,执行的速度就非常的快,之后我where条件中 ...
- 用JS实现的类似QQ密码的输入特效
<input ID="_PSD"></input> <script> function passwordText(ID,pd,mark){ ma ...
- windows server2008 kettle部署
kettle部署需要有jdk环境,所以需要配置环境变量. 1.首先配置jdk,将jdk压缩包解压到c盘下 增加系统变量:JAVA_HOME:c:\jdk 在path后追加: %JAVA_HOME%\b ...
- js代码实现下拉菜单
效果 js代码: <script type="text/javascript"> function ShowSub(li) {//函数定义 var subMenu = ...
- android 学习资源总结
http://android-arsenal.com/free 国外的android分类资源网站 http://www.ibm.com/developerworks/cn/topics/ IB ...
- 【PKU1001】Exponentiation(高精度乘法)
Exponentiation Time Limit: 500MS Memory Limit: 10000K Total Submissions: 145642 Accepted: 35529 ...
- WPF 打印
1. System.Windows.Controls.PrintDialog printDialog = new System.Windows.Controls.PrintDialog(); if ( ...
- 深入理解CSS中的层叠上下文和层叠顺序(转)
by zhangxinxu from http://www.zhangxinxu.com 本文地址:http://www.zhangxinxu.com/wordpress/?p=5115 零.世间的道 ...
- Ubuntu14.04+RabbitMQ3.6.3+Golang的最佳实践
目录 [TOC] 1.RabbitMQ介绍 1.1.什么是RabbitMQ? RabbitMQ 是由 LShift 提供的一个 Advanced Message Queuing Protocol ...
- tomcat war部署根目录下
一个很取巧的办法,步骤如下: 1. 删除webapp下所有文件 cd ${TOMAT_HOME}/webapps && rm -rf * 2. copy待部署war到webapps目录 ...