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. > > > >