我遇到来自Maya 2013 API的示例命令插件的问题。为了清楚起见,插件的代码已被拆分为.h和.cpp文件,但应该是正确的。
pluginCmd.h:
// Include the needed headers.
#include <stdio.h>
#include <maya/MString.h>
#include <maya/MArgList.h>
#include <maya/MFnPlugin.h>
#include <maya/MPxCommand.h>
#include <maya/MIOStream.h>
// Class to represent our command.
class commandExample : public MPxCommand
{
public:
commandExample();
virtual ~commandExample();
MStatus doIt( const MArgList& );
MStatus redoIt();
MStatus undoIt();
bool isUndoable() const;
static void* creator();
};
pluginCmd.cpp:
// Include the header for the file.
#include "pluginCmd.h"
// Constructor for the command object.
commandExample::commandExample() {
cout << "In commandExample::commandExample()\n";
}
// Destructor for the command object.
commandExample::~commandExample() {
cout << "In commandExample::~commandExample()\n";
}
// The actual command/work to be performed.
MStatus commandExample::doIt( const MArgList& ) {
cout << "In commandExample::doIt()\n";
return MS::kSuccess;
}
// The creator is called when the command is invoked and sets up the command object.
void* commandExample::creator() {
cout << "In commandExample::creator()\n";
return new commandExample();
}
// Gets called when the plugin is loaded into Maya.
MStatus initializePlugin( MObject obj ) {
// Set plugin registration info: Author, plugin-version and Maya version needed.
MFnPlugin plugin( obj, "Martin Jørgensen", "1.0", "Any" );
plugin.registerCommand( "commandExample", commandExample::creator );
// Print to show plugin command was registered.
cout << "In initializePlugin()\n";
return MS::kSuccess;
}
// Gets called when the plugin is unloaded from Maya.
MStatus uninitializePlugin( MObject obj )
{
MFnPlugin plugin( obj );
plugin.deregisterCommand( "commandExample" );
// Print to show the plugin was unloaded.
cout << "In uninitializePlugin()\n";
return MS::kSuccess;
}
使用Maya 2013 x64库在Windows 7 x64 Visual Studio 12上成功编译。 当它在插件管理器中加载时,会发生注释(它应该打印初始化状态)。但是当它被卸载时,初始化打印出现。有没有人知道为什么会这样?
答案 0 :(得分:5)
使用Visual Studio 2015和Maya 2016 x64编写插件时遇到同样的问题。
建议的解决方法
cout << "Something out" << endl;
似乎不再有用了。
我发现写入cerr
的内容会显示在Maya的输出窗口中。
因此,作为临时解决方法,我将cout
重定向到cerr
:
cout.rdbuf(cerr.rdbuf());
不理想,但至少我们可以看到输出......
答案 1 :(得分:1)
尝试使用:
cout << "Something out" << endl;
正如PeterT在评论中所建议的那样有效。
作为奖励我已经意识到在调用命令时它没有“挂起”,这是因为命令对象在撤消/重做历史记录中仍处于活动状态。这是我掌握玛雅工作能力的错误。