Re: Palette to write out Global Names to a Selected NB
- To: mathgroup at smc.vnet.net
- Subject: [mg78942] Re: Palette to write out Global Names to a Selected NB
- From: David Reiss <dbreiss at gmail.com>
- Date: Fri, 13 Jul 2007 06:05:59 -0400 (EDT)
- References: <f74rl1$819$1@smc.vnet.net>
Here is one approach:
CreatePalette[
{Button["Glbl Names",
Module[{nb, globals},
globals = Partition[Names["Global`*"], 3, 3, 1, " "];
nb = InputNotebook[];
SelectionMove[nb, After, Notebook];
NotebookWrite[nb,
Cell[BoxData[ToBoxes[Grid[globals, Alignment -> Left]]], "Text",
ShowStringCharacters -> False]];
]]}]
--David
A WorkLife FrameWork
E x t e n d i n g MATHEMATICA's Reach...
http://scientificarts.com/worklife
Compatible with Mathematica 6
On Jul 12, 5:18 am, Donald DuBois <don... at comcast.net> 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