1

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 で正常にコンパイルされます。プラグイン マネージャーに読み込まれると、通知が行われます (初期化ステータスが出力されるはずです)。しかし、アンロードされると、初期化印刷が表示されます。これがなぜなのか、誰にも手がかりがありますか?

4

2 に答える 2

1

使用してみました:

 cout << "Something out" << endl;

PeterT がコメントで示唆したように、これは機能します。

おまけとして、コマンドが呼び出されたときに「ハング」しなかったことに気付きました。これは、元に戻す/やり直しの履歴でコマンドオブジェクトがまだアクティブだったためです。これは、マヤの仕組みを把握する私の能力のミスでした。

于 2013-08-02T19:16:21.797 に答える