1

我对来自 Maya 2013 API的示例命令插件有疑问 为了清楚起见,插件的代码已拆分为 .h 和 .cpp 文件,但在其他方面应该是正确的。

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

4

2 回答 2

5

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

建议的解决方法

cout << "Something out" << endl;

似乎不再起作用了。

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

因此,作为临时解决方法,我重定向coutcerr

cout.rdbuf(cerr.rdbuf()); 

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

于 2016-06-19T09:41:28.693 回答
1

尝试使用:

 cout << "Something out" << endl;

正如 PeterT 在评论中建议的那样,它有效。

作为奖励,我意识到在调用命令时它没有“挂起”,这是因为命令对象在撤消/重做历史记录中仍然处于活动状态。这是我掌握 Maya 工作原理的一个错误。

于 2013-08-02T19:16:21.797 回答