Re: Transparent evalaution of a notebook
- To: mathgroup at smc.vnet.net
- Subject: [mg30704] Re: [mg30540] Transparent evalaution of a notebook
- From: Omega Consulting <omega_consulting at yahoo.com>
- Date: Sat, 8 Sep 2001 02:23:22 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
At 03:54 AM 8/28/2001, Helge Andersson wrote: >Dear Mathematica users > >Can someone give me an example of a command sequence or functions which >Opens another notebook and perform the evaluation of one or more cells >in that notebook. I think opening the nb in the front end and evaluating is not what you want to do. I've seen these requests often and they are usually better served by packages. Here's how you can do this with a package: 1) Open definitions.nb. 2) Select all cells (Edit>Select All) and make them Initialization cells (Cell>CellProperties>Initialization Cell). 3) Use File>Save As Special>Package format to create the file definitions.m 4) Close definitions.nb 5) Make the first cell in abc.nb a Get command that loads definitions.m You don't need to create a "formal" package (with Begin, BeginPackage, etc.). A package can contain any valid Mathematica input, just like a nb. So I wouldn't worry about whether the functions are "general enough". If it works in a nb, it will work in a package (except that output is suppressed). >To be more specific: > >I have the notebook abc.nb where I do some calculations using >predefined variables, lists and functions which I dont want to define >in abc.nb. I have a Notebook called definitions.nb where I keep my >definitions of variables, list and functions. When I start to work with >my calculations in abc.nb, I want to evaluate one cell in abc.nb (the >first cell for example) which > >1. Opens definitions.nb , >2. Evaluate the cells in definitions.nb >3. Close definitions.nb after the evaluation in step 2 If you must do this in the front end, things get very sticky because of the order of evaluation. You can: 1) Make the last cell in definitions.nb NotebookClose[EvaluationNotebook[]] 2) Make the first cell in abc.nb nb=NotebookOpen["definitions.nb"]; (* may need full path here *) SelectionMove[nb, All, Notebook]; SelectionEvaluate[nb]; This will work, but you *must* evaluate this first cell in abc.nb by itself. If you evaluate any other cells in abc.nb with the first cell, the cells in abc.nb will evaluate *before* the cells in definitions.nb. Get of a package does not suffer from this limitation. >I should say that the functions in definitions.nb are not so general >that I want to implement them as packages. I also know that I can use >one or two evenings reading the help menu but I try this way first as a >possible time-saver. I work on Window 2000 machine with Mathematica >4.1. > > >Helge Andersson > > >Chalmers University of Technology >SE-412 96 Sweden