Search code examples
c++visual-studiopluginsmaya

Maya plugin console-out not writing


I have a problem with the example command plugin from the Maya 2013 API The code for the plugin have been split into a .h and a .cpp file for clarity, but should be otherwise correct.

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;
}

It is compiled successfully on Windows 7 x64 Visual Studio 12 with Maya 2013 x64 libraries. When it is loaded in the plugin manager, noting happens (it should print the initialize status). But when It is unloaded, the initialize print shows up. Does anyone have a clue to why this is?


Solution

  • Tried using:

     cout << "Something out" << endl;
    

    as PeterT suggested in a comment, which works.

    As a bonus I have realised that it did not "hang" when the command was called, it was because the command object was still active in the undo/redo history. This was a mistake in my ability to grasp Maya's workings.