Forwarding System.Console info to Rhino command line console

Hello there,

for my Rhino/Grasshopper plugin in C#, I’m using an external foo.dll which prints important information to the System.Console. Now this info doesn’t show up anywhere obviously as I’m not calling foo.dll from the windows command line but from inside Rhino. Is there a way to forward this System.Console info to the Rhino command line console directly without invoking Rhino.RhinoApp.WriteLine whenever I call a command from foo.dll?
I tried something like:

System.Console.SetOut(Rhino.RhinoApp.CommandLineOut);

…without success. I assume that RhinoApp.CommandLineOut itself is sending things to the system.console and not to the rhino console. Right?

Any suggestion would be a great help
Best
Ben

Hi @Benjamin1,

This seems to work from a plug-in command:

protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
  Console.SetOut(RhinoApp.CommandLineOut);
  Console.WriteLine("Hello Rhino!");
  return Result.Success;
}

What am I missing?

– Dale

Hi Dale!

thanks for the reply! My problem is, that I’m not calling

Console.WriteLine(“Hello!”)

within the plugin.gha. The console info is generated in the referenced foo.dll. I thought that this console info would naturally be forwarded to plugin.gha as it sets the scope for foo.dll functions.
(side note: foo actually consists of two parts: fooCore.dll (C++) and fooCLI.dll (C++/CLI). fooCLI.dll only serves to forward calls from plugin.gha to fooCore.dll and vice versa; so plugin.gha only makes calls into fooCLI.dll and in return receives console info that is generated with std::cout calls in fooCore.dll)
However, when I’m using fooCLI.dll from a testing ConsoleApplication.cs, the console info (coming from fooCore.dll) is shown in the command window. So the info does arrive in the C# context of ConsoleApp.exe. But when I plug things together inside plugin.gha using

Console.SetOut(RhinoApp.CommandLineOut);

it seems to loose track of that info stream.
Also calls to fooCLI.dll are made from a different thread inside plugin.gha. So I’d have to make it thread safe somehow. Earlier I used

RhinoApp.InvokeOnUiThread(new Action(() => Rhino.WriteLine(“Hello!”)));

…but I want to avoid doing this manually
Hope that’s not too much to ask for.

Thanks a lot already!
Ben