Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

How is it possible to send the whole content of an existing notebook to Mathematica for evaluation by using NetLink/C#?

share|improve this question
add comment

1 Answer 1

To evaluate a notebook from .NET, a batch file and a package file can be used. This example opens and evaluates a notebook called "run.nb" in the front end. Ref:- http://stackoverflow.com/q/7626491/879601

i.e. batch file:-

@echo off
setlocal
PATH = C:\Program Files\Wolfram Research\Mathematica\8.0\;%PATH%
start MathKernel -noprompt -initfile "C:\Temp\test.m"
endlocal

and package file, "test.m":-

Needs["JLink`"];
$FrontEndLaunchCommand="Mathematica.exe";
UseFrontEnd[
nb = NotebookOpen["C:\\Temp\\run.nb"];
SelectionMove[nb, All, Notebook];
SelectionEvaluate[nb];
];
Pause[10];
CloseFrontEnd[];

The batch file and package file can be created on the fly and run from .NET, (or perhaps you could execute the start command directly and dispense with the batch file).

Alternatively, you could run the main notebook (as a package) in Mathematica script mode. The above answer uses the front end in order to save output cell information.

Your question mentions evaluating an existing notebook, but if you also need to create the notebook in .NET this post may be of use:- http://stackoverflow.com/a/7321479/879601

share|improve this answer
    
Hi. Thank you for your answer. If I understand you correct, there is now possibilty to use .netLink to evaluate an existing notebook?!? Is ist possible to send parameters to the batch file and also return results? Thank you –  user6511 Mar 25 '13 at 6:17
    
@user6511 - the batch file can be created in .NET on the fly. Retrieval of results from the evaluated notebook depends on the notebook writing data somewhere where it can be read back in by a .NET program. Otherwise you can get the notebook to save its output using NotebookSave. –  Chris Degnen Mar 25 '13 at 9:44
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.