gpt4 book ai didi

c++ - Maya 插件控制台输出不写入

转载 作者:行者123 更新时间:2023-11-30 00:52:52 50 4
gpt4 key购买 nike

我对来自 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();
};

插件命令.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 上成功编译。当它在插件管理器中加载时,会发生注释(它应该打印初始化状态)。但是当它被卸载时,初始化打印出现了。有谁知道这是为什么?

最佳答案

我在使用 Visual Studio 2015 和 Maya 2016 x64 编写插件时遇到了同样的问题。

建议的解决方法

cout << "Something out" << endl;

似乎不再起作用了。

我发现写入 cerr 的内容确实显示在 Maya 的输出窗口中。

因此,作为临时解决方法,我将 cout 重定向到 cerr:

cout.rdbuf(cerr.rdbuf()); 

不理想,但至少我们可以看到输出...

关于c++ - Maya 插件控制台输出不写入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18022233/

50 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com