3

If I open a notebook in Mathematica, and type "nb=NotebookCreate[]", it creates a new notebook window, as expected.

However, if I try the same command from within C#, it fails, and doesn't open a new notebook window:

IKernelLink ml = MathLinkFactory.CreateKernelLink();
ml.WaitAndDiscardAnswer();
string cmd = @"nb = NotebookCreate[]";
string result = ml.EvaluateToOutputForm(cmd, 0);

// result is now "$Failed".

Note that if I pass in "2+2", it returns "4", which proves the link to the Mathematica kernel is working perfectly well.

Mr.Wizard
  • 24,179
  • 5
  • 44
  • 125
Contango
  • 76,540
  • 58
  • 260
  • 305
  • p.s. One of the reasons why it would be amazing to get this working is so I could pump debugging information from my C# console app into an interactive workbook in Mathematica, particularly interactive 3-D graphs. – Contango Sep 26 '12 at 16:37
  • 1
    Notebook created directly from box data using C# in this example, might be of some use to you: http://stackoverflow.com/a/7321479/879601 – Chris Degnen Sep 26 '12 at 19:49
  • You might get a better response if you have this migrated to http://mathematica.stackexchange.com -- flag it for moderator attention and request this if you choose. – Mr.Wizard Sep 27 '12 at 06:57
  • Another link that could help: http://stackoverflow.com/a/8279901/879601 – Chris Degnen Sep 29 '12 at 08:42

1 Answers1

0

Unfortunately, it appears as if this is impossible for Mathematica v8 (and I don't think much has changed in v9).

From what I understand, when you access the Mathematica kernel from C#, this does not allow access to the Notebook classes, which are part of the GUI.

Contango
  • 76,540
  • 58
  • 260
  • 305
  • Are you sure it is impossible? `NotebookCreate[]` requires `$FrontEnd` to be defined (that is the FrontEnd must be launched and connected to the kernel). I suspect that you simply have not connected the FrontEnd. Try to evaluate `NotebookCreate[]` in pure MathKernel session - you will get `$Failed` as expected. – Alexey Popkov Jan 28 '13 at 12:20