Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive

MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: How to evaluate a notebook programmatically?

  • To: mathgroup at
  • Subject: [mg98607] Re: How to evaluate a notebook programmatically?
  • From: mike.honeychurch at
  • Date: Tue, 14 Apr 2009 06:16:11 -0400 (EDT)
  • References: <grupsj$rf$>

On Apr 13, 2:33 am, "Paul Ellsmore" <paul.ellsm... at>
> Hi,
> In one notebook, "gui.nb", I have the code for a user interface. In anoth=
> "functional.nb" I have around 3000 lines of code, in several hundred cell=
> I want to click a button (or something similar) in gui.nb, and tell
> Mathematica to execute all the cells in functional.nb. Functional.nb will
> use values for global variables that have been assigned in gui.nb, and
> gui.nb will display the results of the execution of functional.nb. Seems
> straightforward.
> Now in functional.nb, we group all the cells together, so that we can
> manually execute them all with a single shift-click. What is the
> programmatical equivalent of this? I have looked through all the tutorial=
> etc on controlling notebooks from the front end, frontendtokens etc., but
> nothing seems to do quite what I want. The options seem to be:
> Option 1. Merge all the cells in functional.nb, and assign that cell to a
> Function, which can then be called from gui.nb. This is highly undesirabl=
> because if an error occurs, we find out about it at the end of 3000 lines=
> code, with no idea where the error occurred. The cell structure in
> Mathematica is just too valuable to throw away. I guess that using workbe=
> might mitigate some of these issues, but that means my colleagues and I a=
> having to learn a new (and complicated) tool.
> Option 2. Assign each of the (hundreds of!) cells to a separate function,
> and call each of them in turn from gui.nb. A lot of hard work here with t=
> potential for errors in naming and ordering the functions in the two
> notebooks, and probably an increase in execution time.
> Option 3. Make all the cells in functional.nb initialization cells, then =
> gui.nb to open functional.nb each time we want to evaluate it, and then
> close it again. Very clunky, and again probably slow.
> I am sure there are better options than these? Any ideas?
> Thanks,
> Paul.
> Dr. Paul A. Ellsmore
> Nanion Limited
> Oxford Centre for Innovation
> Mill Street
> Oxford
> United Kingdom
> OX2 0JX
> Tel: +44 (0) 1865 811175
> Fax: +44 (0) 1865 248594

without seeing the notebooks my guess would be that you might want to
do something like to tag the cells that you want to group and evaluate
together, then use NotebookFind to locate those tagged cells and then
SelectionEvaluate. Those steps could be combined into a function

evaluteCells[yourTags_String]:=(NotebookFind[nb, "yourTags", All,

where nb=EvalutionNotebook[]


  • Prev by Date: Re: How to evaluate a notebook programmatically?
  • Next by Date: Re: Should I be using Mathematica at all?
  • Previous by thread: Re: How to evaluate a notebook programmatically?
  • Next by thread: Re: How to evaluate a notebook programmatically?