C++ API: not printing to output window

C++ API: not printing to output window

Anonymous
Not applicable
13,035 Views
37 Replies
Message 1 of 38

C++ API: not printing to output window

Anonymous
Not applicable
Hello,

I'm having some trouble with printing to the Output Window using cout (or printf, for that matter). It seems to work some of the time, and not others. I haven't been able to find a pattern yet. All other features of the api seem to be working.

I'm wondering if anyone might know what conditions need to be met to ensure that the standard output is properly sent to the Output Window.

Thanks in advance.
0 Likes
13,036 Views
37 Replies
Replies (37)
Message 21 of 38

Anonymous
Not applicable

Encountered similar problem in Maya2018. Was able to resolve by compiling the code in Debug/ReleaseDebug configuration.

ReleaseDebug is similar to Hybrid configuration for compilation.

 

Have fun coding.

0 Likes
Message 22 of 38

Anonymous
Not applicable

I had the problem with Maya 2016 and

std::cout.set_rdbuf(MStreamUtils::stdOutStream().rdbuf());
std::cerr.set_rdbuf(MStreamUtils::stdErrorStream().rdbuf());

helped. It works with std::endl here, so

std::cerr << "Hello" << std::endl;

runs fine.

 

Before I had the strange issue, that it only worked in debug configuration here, but worked in release configuration for the client.

0 Likes
Message 23 of 38

puch
Explorer
Explorer

I just opened a support request about this subject yesterday before finding this thread. I'm using VS 2015 with Maya 2018 as specified by the documentation. This problem is really annoying and it should be fixed. The workaround of doing:

 

std::cout.set_rdbuf(MStreamUtils::stdOutStream().rdbuf());
std::cerr.set_rdbuf(MStreamUtils::stdErrorStream().rdbuf());

 

even though really ugly seems to solve my problem.

 

Autodesk, can we have a bug number so we can track the progress of this in the future?

Message 24 of 38

zhong_wu
Autodesk Support
Autodesk Support

Actually, this should not be a bug, according to our test, std::cerr() should still work in release mode of your plugin, but for debug mode, it's not guaranteed because you cannot usually mix Debug and Release binaries as the CRTs are different. 

 

As you may noticed, std::cerr() seems worked before in debug mode with Maya 2017, but since we upgraded to Visual Studio 2015 between Maya 2017 and Maya 2018, as I said, the behavior may change fundamentally by Microsoft.   

 

Let me know if this makes scenes or any other comments. 


John Wu
Developer Technical Services
Autodesk Developer Network


0 Likes
Message 25 of 38

Anonymous
Not applicable

With maya2016 I had the problem the other way round and the output did only work in debug mode. For the client it worked in release mode.

 

Is there a reason against integrating the workaround in future maya releases? It seem to work really fine without causing any other problems.

0 Likes
Message 26 of 38

zhong_wu
Autodesk Support
Autodesk Support

Hi Alex, what do you mean by integrating the workaround in future maya releases? 


John Wu
Developer Technical Services
Autodesk Developer Network


0 Likes
Message 27 of 38

Anonymous
Not applicable

I am using the lines posted above in all plugins and they work very well.

I guess maya could do the same just before loading the plugin, so the plugin authors don't need to fix it themself.

0 Likes
Message 28 of 38

michaelkdaw
Enthusiast
Enthusiast

There should be "MGlobal::WriteToOutputWindow()" or something similar.

0 Likes
Message 29 of 38

puch
Explorer
Explorer

Unfortunately the above trick works fine on Windows but it doesn't work on OSX and Linux. On CentOS 6.5 for instance I get:

 

/home/myUser/test/testPlugin/source/testPluginPlugIn.cpp:61:13: error: ‘std::ostream’ has no member named ‘set_rdbuf’
   std::cout.set_rdbuf(MStreamUtils::stdOutStream().rdbuf());
             ^
/home/myUser/test/testPlugin/source/testPluginPlugIn.cpp.cpp:62:13: error: ‘std::ostream’ has no member named ‘set_rdbuf’
   std::cerr.set_rdbuf(MStreamUtils::stdErrorStream().rdbuf());


 

0 Likes
Message 30 of 38

kollig
Advocate
Advocate

Use

streambuf* rdbuf (streambuf* sb);

 to set the buffer. This works at least on Windows and Linux.

0 Likes
Message 31 of 38

Anonymous
Not applicable

Are you sure? I mean no one can pass the helloCmd.cpp plugin and it is not a bug?

I am using a MacOS, and none of the codes above works for me, even std::cerr().

Plz

 

0 Likes
Message 32 of 38

Anonymous
Not applicable

I can't get any of the above suggestions to work?! 

I'm running Maya 2018.3 and VS2015 Update 3

 

How can this not be a priority for Autodesk to get fixed?! HelloWorld is the first plugin anyone would start out with and it doesn't work?!?

0 Likes
Message 33 of 38

michaelkdaw
Enthusiast
Enthusiast

While writing to the output window may be handy, I wouldn't really consider it to be the "HelloWorld" of Maya plugins. You can still use MGlobal::displayInfo("Hello World") for writing to the script editor for most of your diagnostic needs.

Message 34 of 38

danwwright
Participant
Participant

I'm trying to come up to speed on writing my first C++ plugin-


@michaelkdaw wrote:

While writing to the output window may be handy, I wouldn't really consider it to be the "HelloWorld" of Maya plugins. You can still use MGlobal::displayInfo("Hello World") for writing to the script editor for most of your diagnostic needs.



@michaelkdaw wrote:

While writing to the output window may be handy, I wouldn't really consider it to be the "HelloWorld" of Maya plugins. You can still use MGlobal::displayInfo("Hello World") for writing to the script editor for most of your diagnostic needs.




and I've just wasted an entire day on this stupid issue.

I'm using Maya 2019 and Visual Studio 2015.

 

Until this is fixed please just add the warning "this sample doesn't work!!" to keep others from wasting too much time on this too...

Message 35 of 38

michaelkdaw
Enthusiast
Enthusiast

Does anyone know how to edit posts? I'd like to mention what danwwright has said in an edit of the original post to hopefully keep people from wasting any more time then they need to on this issue.

0 Likes
Message 36 of 38

Anonymous
Not applicable

Maybe i konw the reason why it cant work. i use vs2017 build for maya 2017, also i change the code of hello world. Then i found cout cant work.

 

so i use the vs2012 that mentioned at maya2017help,the cout work.

 

then i change the toolkit of vs2017,it's also worked.

 

so it maybe the MS change the toolkit without saying anything about it.

 

FZgGbh1m7SUNt2O

 

 

0 Likes
Message 37 of 38

olarn
Advocate
Advocate

Why not just straight up use whatever maya hand out as output stream instead?

 

MStreamUtils::stdOutStream() << "some msg" << var << std::endl;

Message 38 of 38

davedub
Participant
Participant

Amazingly, this is still an issue with the Maya 2023 C++ plugin example with VS2019.
The only way I could get any output in the console was to use MGlobal::displayInfo("Hello World") after including MGlobal.h

The fact that Autodesk left a non-functioning tutorial for beginners online for all these years is mind boggling.