4
$\begingroup$

I have two Notebooks and I call the second Notebook from the main but main Notebook's expressions continue executing. I want them to wait until the second Notebook's expressions execution is finished!

My main Notebook's code is such as:

docpath = ToFileName[{"C:", "Users"}, "MATHEMATICA"];

nbLBDxi = NotebookOpen[ToFileName[docpath, "LBDxi.nb"]];

SelectionMove[nbLBDxi, All, Notebook];

SelectionEvaluate[nbLBDxi];

NotebookClose[nbLBDxi];
  • Here the main Notebook's other expressions, which I won't write for brevity, will come but I want them to wait until the above expressions' execution is over.
$\endgroup$

1 Answer 1

5
$\begingroup$

Probably you should use NotebookEvaluate instead of SelectionEvaluate. According to the Documentation,

By default, NotebookEvaluate evaluates the cells of a notebook in the same way that Get evaluates the lines of a package file.

For example try:

nb = CreateDocument[ExpressionCell[Defer[Pause[10]], "Input"]];
NotebookEvaluate[nb]
Print["!"]

The Print["!"] statement is evaluated only when evaluation of the Notebook nb is finished!

$\endgroup$
2
  • $\begingroup$ Thank you @Alexey Popkov your reccomendation, using NotebookEvaluate instead of SelectionEvaluate, solved the problem. $\endgroup$
    – ahmethasim
    Jun 27, 2016 at 12:09
  • $\begingroup$ @ahmethasim Then you can Accept my answer by clicking the green checkmark. $\endgroup$ Jun 27, 2016 at 12:14

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.

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