Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2001
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2001

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

Search the Archive

RE: Loop through a notebook

  • To: mathgroup at smc.vnet.net
  • Subject: [mg31681] RE: [mg31662] Loop through a notebook
  • From: Mikael Adlers <mikael at mathcore.com>
  • Date: Sat, 24 Nov 2001 16:43:52 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

Hi,
there are several way to loop through all the cells in a notebook.
Use SelectionMove to move from cell to cell, this command will step
through subcells e.t.c.. I use AutoScroll->False so the notebook
do not scroll during the process. nb is a variable containing
a NotebookObject.

An example to pick out the evaluatble cells in a notebook:

SelectionMove[nb, Before, Notebook, AutoScroll -> False];
SelectionMove[nb, Next, Cell, AutoScroll -> False];
(* If the selection is at the end of the notebook evalOpt will be $Failed *)
evalOpt = Options[NotebookSelection[nb], Evaluatable];
While[evalOpt =!= $Failed,
	If[Evaluatable /. evalOpt,
		(* Do your stuff *)
		SelectionEvaluate[nb];
	];
	evalOpt = Options[NotebookSelection[nb], Evaluatable];
]

or if you would like to pick out all the cell and do something you
could use:

SelectionMove[nb, Before, Notebook, AutoScroll -> False];
SelectionMove[nb, Next, Cell, AutoScroll -> False];
currentCell = NotebookRead[nb];

While[currentCell =!= {},
  If[StringMatchQ[currentCell[[2]], "*Text*"],
    (* Do something to the text cell *)
    ];
  SelectionMove[nb, Next, Cell, AutoScroll -> False];
  currentCell = NotebookRead[nb];
  ];


Regards,
/Mikael A.


------------------------------------------------------------------ 
 Mikael Adlers, Ph.D.          email: mikael at mathcore.com 
 MathCore AB                   phone: +4613 32 85 07 
 Wallenbergsgata 4             fax:         21 27 01
 SE-583 35 Linköping, Sweden   http://www.mathcore.com



> -----Original Message-----
> From: Adam BOUCHTA [mailto:Adam.Bouchta at cern.ch] 
To: mathgroup at smc.vnet.net
> Sent: den 23 november 2001 11:47
> Subject: [mg31681] [mg31662] Loop through a notebook
> 
> 
> How does one loop through a notebook which contains sections, 
> subsections,
> etc.?
> 
> A for or do-loop do not work...
> 
> 
> 
> /Adam.
> 
> 
> 
> 


  • Prev by Date: Re: Aligning subplots nicely?
  • Next by Date: RE: Aligning subplots nicely?
  • Previous by thread: Loop through a notebook
  • Next by thread: Re: Loop through a notebook