Re: Deleting parts of notebooks programmatically
- To: mathgroup at smc.vnet.net
- Subject: [mg89230] Re: Deleting parts of notebooks programmatically
- From: David Reiss <dbreiss at gmail.com>
- Date: Fri, 30 May 2008 02:56:50 -0400 (EDT)
- References: <g1m8il$ju$1@smc.vnet.net>
It seems like the problem that you are having with your Manipulates not rendering is a bug. It certainly doesn't happen if the material is copied and pasted "by hand." So this suggests using a temporary notebook to write the material to and then to copy and paste it into the desired notebook. In the following nb is the NotebookObject of the notebook that you want to remove the part of. I am omitting the part replacement code here: thenb = NotebookGet[nb]; tempnb = CreateDocument[{}, Visible -> False]; NotebookPut[thenb, tempnb]; SelectionMove[tempnb, All, Notebook]; FrontEndExecute[FrontEndToken[tempnb, "Copy"]]; SelectionMove[nb, All, Notebook]; FrontEndExecute[FrontEndToken[nb, "Paste"]]; NotebookClose[tempnb] I hope that this helps... --David On May 29, 8:46 am, "J. McKenzie Alexander" <ja... at lse.ac.uk> wrote: > Suppose that I have a part specification (as returned by Position) for = > a component of the current InputNotebook[] that I would like to > delete, and that this part specification was determined > programmatically. As a first guess I would try to use the function > NotebookDelete - except that only deletes the current *selection* in > the specified notebook, and there doesn't seem to be any easy way of > using SelectionMove to set the current selection so as to correspond > exactly to the region given by a part specification... > > The only solution I've found is the following:: > > nb = NotebookGet[ InputNotebook[] ]; > pos = Position[ nb, ..... ]; > NotebookPut[ Delete[nb, pos], InputNotebook[] ] > > The problem is that this breaks any Manipulates appearing in the > notebook (any displayed graphic appears greyed out and doesn't ever > display correctly again until the notebook is closed and re-loaded). > > In case anyone wants to see what motivates this, and an example > showing the Manipulate bug, here's a simple notebook which implements > endnotes in Mathematica (version 6 and higher). Do keep in mind that = > it's a beta, and not very robust yet. > > http://evolve.lse.ac.uk/~jalex/files/Endnotes.nb > > Cheers, > > Jason > > -- > Dr J. McKenzie Alexander > Department of Philosophy, Logic and Scientific Method > London School of Economics and Political Science > Houghton Street, London WC2A 2AE > > Please access the attached hyperlink for an important electronic communica= tions disclaimer:http://www.lse.ac.uk/collections/secretariat/legal/disclaim= er.htm