Re: Notebook manipulation
- To: mathgroup at smc.vnet.net
- Subject: [mg32974] Re: [mg32824] Notebook manipulation
- From: Dale Horton <daleh at wolfram.com>
- Date: Fri, 22 Feb 2002 01:49:00 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
At 12:43 AM 2/14/2002, Roger Mason wrote: >Hello, > >Firstly, thanks to Paul Hinton of WRI for his help with my last >question. > >Secondly, I have been attempting to use the notebook manipulation >functions to get some output written into a notebook that is created by >the kernel. The idea is then to save or print the new notebook. By >following section 2.10.3 of the on-line help, I have been able to write >data into the new notebook and perform evaluation on the data. However, >on saving or printing the new notebook the output cells are never >present. > >Clearly, I am missing something. What am I doing wrong? Some code is >appended. > >Thanks, > >Roger Mason. >Mathematica 4.0, Linux RH7.0. > >nb = NotebookCreate[]; >(*nb = SelectedNotebook[];*) >NotebookWrite[nb, "10!", All]; >SelectionEvaluateCreateCell[nb, All]; >NotebookApply[nb, "\[SelectionPlaceholder]/2", All ]; >SelectionEvaluateCreateCell[nb, Before]; >NotebookSave[nb, "notebook.nb"]; >(*NotebookPrint[nb, "/home/rmason/test.ps", > PrintingStyleEnvironment -> "Printout"];*) >NotebookClose[nb]; Just because SelectionEvaluateCreateCell comes before NotebookSave, it doesn't mean that the actual evaluation occurs before the NotebookSave. http://support/mathematica/kernel/interface/selectionevaluate.html SelectionEvaluateCreateCell is like a Shift-Enter. It queues the evaluation, but there's already an evaluation in the kernel (the code you're running). NotebookSave and NotebookClose are frontend operations, however, and do not wait for the kernel. They act immediately. So the stuff in nb isn't set to evaluate until after your code is done, but by then nb is already saved and closed. -Dale