Re: Loop through a notebook

*To*: mathgroup at smc.vnet.net*Subject*: [mg31718] Re: [mg31662] Loop through a notebook*From*: Omega Consulting <omega_consulting at yahoo.com>*Date*: Wed, 28 Nov 2001 01:29:43 -0500 (EST)*Sender*: owner-wri-mathgroup at wolfram.com

At 04:46 AM 11/23/2001, Adam BOUCHTA wrote: >How does one loop through a notebook which contains sections, subsections, >etc.? > >A for or do-loop do not work... > > > >/Adam. It depends on why you want to loop through the notebook. Often, what you really want is some way to act on different parts of a notebook. This can be done by getting the notebook, modifying it and putting it back out. This is often easier to program and faster than a loop. For example, to remove all output from a nb cont = NotebookGet[nb]; cont = DeleteCases[cont, Cell[_, "Output"|"Print"|"Graphics", ___], Infinity]; NotebookPut[cont, nb] If you really want or need a loop, then it's just a matter of SelectionMove. SelectionMove[nb, Before, Notebook, AutoScroll->False]; SelectionMove[nb, Next, Cell, AutoScroll->False]; cont = NotebookRead[nb]; While[cont=!={}, SelectionMove[nb, Next, Cell, AutoScroll->False]; cont = NotebookRead[nb]; If[MatchQ[cont, Cell[_, "Output"|"Print"|"Graphics", ___]], NotebookDelete[nb] ] ] -------------------------------------------------------------- Omega Consulting "The final answer to your Mathematica needs" Spend less time searching and more time finding. http://www.wz.com/internet/Mathematica.html