Re: Palette to write out Global Names to a Selected NB
- To: mathgroup at smc.vnet.net
- Subject: [mg78958] Re: Palette to write out Global Names to a Selected NB
- From: dh <dh at metrohm.ch>
- Date: Fri, 13 Jul 2007 06:14:21 -0400 (EDT)
- References: <f74rl1$819$1@smc.vnet.net>
Hi Don, you have to format using ToBoxes your expression before writing it. However, you are doing this much too clumsy. There is no need to write a string and then execute it. Here is a simpler version: CreatePalette[{Button["Glbl Names",With[{nb=InputNotebook[]},SelectionMove[nb,After,Notebook]; d=Grid[Partition[Names["Global`*"],3]]; NotebookWrite[nb,ToBoxes[d]]; ]]}] hope this helps, Daniel Donald DuBois wrote: > Hello, > > I am trying to create a Palette with a button which, > when clicked, will write out the Global names > (i.e. Names["Global`*"] ) to the notebook which is currently selected. > > The following code works and puts out a linear list of > the global names: > > CreatePalette[ > { > Button["Glbl Names", > With[{nb = InputNotebook[]}, SelectionMove[nb, After, Notebook]; > NotebookWrite[nb, Cell["Names[\"Global`*\"]"]]; > > SelectionMove[nb, All, CellContents]; > SelectionEvaluate[nb] > ] > ] > } > ] > > > The above code produces correctly, in the selected notebook, the list: > > {"a52", "a53", "data1", "m1", "m2", "m3", "nb", "nb$", "var1", "var2"} > > > However, when I try to use Grid in order to format the > linear list of names for readability, (useful if there > are many names) I can't get the Grid function to work: > > CreatePalette[ > { > Button["Glbl Names", > With[{nb = InputNotebook[]}, SelectionMove[nb, After, Notebook]; > NotebookWrite[nb, > Cell["Grid[Partition[Names[\"Global`*\"],3,3,1,\" \"]]"]]; > > SelectionMove[nb, All, CellContents]; > SelectionEvaluate[nb] > ] > ] > } > ] > > This code produces in the selected notebook: > > Grid[{{"a52", "a53", "data1"}, {"m1", "m2", "m3"}, {"nb", "nb$", "var1"}, > {"var2", " ", " "}}] > > > Any help to get Grid to work would be greatly appreciated. Thank you. > > Don >