1
$\begingroup$

I have gotten a tremendous amount of information from the question posted at (Load a Mathematica Package via .Net code), which my application is very similar to. Specifically in that thread, the author uses:

MathKernel k = new MathKernel();  //Establishes a Mathematica kernel  
k.Compute("<< XYZ`XYZGraphs`");   //Runs an entire package file   
string res = k.Result.ToString(); //Collects the result of the file

I was wondering if there was a similar process for a Notebook file? When I tried referencing a Notebook file in the same manner, the math kernel returns $Failed as the result.

Other solutions I thought might work but have not had any success with have been using IKernelLink and IMathLink, or converting the Notebook file to a Package file. I also saw a thread about running from the command line but I am not sure how I would get the results of the Notebook back into .Net using that method.

I would greatly appreciated any advice, thanks!

$\endgroup$
3
  • $\begingroup$ Notebooks contain a lot of content which doesn't mean anything to the Kernel, they're loaded by the FrontEnd. This is the process you can see running called Mathematica rather than MathKernel when you run Mathematica directly. In interactive operation the frontend sends expressions to the kernel from a notebook. $\endgroup$
    – Ymareth
    Jan 30, 2014 at 16:40
  • 1
    $\begingroup$ As Ymareth said, notebooks are not made for this purpose and you should not try to use them this way. You were on the right track when you were thinking of converting the notebook to a package (i.e. plain text file with .m extension and Mathematica commands within). How to do that is explained here. $\endgroup$
    – Szabolcs
    Jan 30, 2014 at 16:50
  • $\begingroup$ @Szabolcs That is exactly the type of information I needed to move forward. Thank you! $\endgroup$
    – Josh
    Jan 30, 2014 at 17:03

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.