NotebookEvaluate

NotebookEvaluate[notebook]

evaluates all the evaluatable cells in notebook.

Details and Options

  • NotebookEvaluate returns the value returned by the last evaluation in the specified notebook.
  • NotebookEvaluate can take either a NotebookObject or a file name referencing a notebook file. If a file name references a notebook that is presently open, then evaluation proceeds on the open notebook.
  • The following options can be given:
  • InsertResults Falsewhether to insert results into notebook
    EvaluationElements Allwhich cells to evaluate
  • By default, NotebookEvaluate displays the side effects of evaluation similarly to how a call to Get would. Messages, print output, and other side effects will be placed as output to the cell that called NotebookEvaluate rather than in notebook. Existing output cells in notebook will not be updated or deleted.
  • NotebookEvaluate[notebook,InsertResults->True] handles side effects and outputs as they would be handled in a TemplateBox[{shift, return}, Key1, BaseStyle -> {Notes, FontWeight -> Plain, FontFamily -> Source Sans Pro}] evaluation. Messages, print output, and other side effects are placed in notebook along with outputs, and will replace any existing output or side effect cells.
  • When NotebookEvaluate[notebook,InsertResults->True] is used on a file that is not open, the Wolfram System will invisibly open the file, evaluate it entirely, save, and close the file.
  • NotebookEvaluate[notebook,InsertResults->False] will leave notebook completely unmodified.
  • The cells of notebook are evaluated in a dialog subsession.
  • Using NotebookEvaluate on an open notebook will cause the visible artifacts of subsession evaluation to occur in that notebook. The notebook will continue to be updated on screen as necessary while its cells are being evaluated.
  • Unlike Get, the presence of a syntax error in an evaluatable cell will not prevent NotebookEvaluate from evaluating other inputs.
  • NotebookEvaluate[notebook,EvaluationElements->Automatic] evaluates only the initialization cells. This is equivalent to saving the notebook as a package file, or with an automatically generated package file, and using Get on the resulting package file.
  • When run on a package file, NotebookEvaluate is equivalent to Get. The InsertResults option will be ignored.

Examples

open allclose all

Basic Examples  (1)

Create a notebook:

Evaluate the notebook and return the result:

Generalizations & Extensions  (1)

NotebookEvaluate can be nested:

Options  (3)

InsertResults  (2)

Insert results in the target notebook:

By default, messages go into the output:

With InsertResults->True, the messages go to the target notebook instead:

EvaluationElements  (1)

Evaluate only initialization cells in a notebook:

Applications  (1)

Create buttons that selectively evaluate cells in a notebook:

Properties & Relations  (2)

% works in notebooks targeted by NotebookEvaluate:

NotebookEvaluate works with session history, and the return value is not suppressed by ;:

Possible Issues  (2)

Notebooks evaluate in their default context, which may be different from the context used by NotebookEvaluate:

If the contexts need to be the same, it may be necessary to set the CellContext option of the notebook:

Evaluation history is scoped to the notebook being evaluated:

Wolfram Research (2010), NotebookEvaluate, Wolfram Language function, https://reference.wolfram.com/language/ref/NotebookEvaluate.html.

Text

Wolfram Research (2010), NotebookEvaluate, Wolfram Language function, https://reference.wolfram.com/language/ref/NotebookEvaluate.html.

CMS

Wolfram Language. 2010. "NotebookEvaluate." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/NotebookEvaluate.html.

APA

Wolfram Language. (2010). NotebookEvaluate. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/NotebookEvaluate.html

BibTeX

@misc{reference.wolfram_2024_notebookevaluate, author="Wolfram Research", title="{NotebookEvaluate}", year="2010", howpublished="\url{https://reference.wolfram.com/language/ref/NotebookEvaluate.html}", note=[Accessed: 18-November-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_notebookevaluate, organization={Wolfram Research}, title={NotebookEvaluate}, year={2010}, url={https://reference.wolfram.com/language/ref/NotebookEvaluate.html}, note=[Accessed: 18-November-2024 ]}