Re: Extracting graphics from notebook
- To: mathgroup at smc.vnet.net
- Subject: [mg115447] Re: Extracting graphics from notebook
- From: Albert Retey <awnl at gmx-topmail.de>
- Date: Tue, 11 Jan 2011 06:58:13 -0500 (EST)
- References: <iggq6a$4gt$1@smc.vnet.net>
Am 11.01.2011 06:35, schrieb Chris Degnen:
> Hi, Can anyone suggest how I can address a graphics object from a
> saved notebook. In the example below the most I can do is to
> CellPrint the object, but I would like to set it to a variable.
>
>
> dir = Directory[];
>
> nb1 = CreateDocument[Plot[Sin[x], {x, 0, 2 Pi}],
> NotebookFileName -> dir <> "\\" <> "Sin2Pi.nb"];
>
> NotebookSave[nb1];
> NotebookClose[nb1];
>
> nb2 = NotebookOpen[dir <> "\\" <> "Sin2Pi.nb"];
>
> SelectionMove[nb2, Next, Cell]
>
> CellPrint[NotebookRead[nb2]]
> NotebookClose[nb2];
the NotebookRead returns the cell expression. You can extract the
Graphics with something like this:
content = NotebookRead[nb2];
Cases[content, GraphicsBox[args___] :> Graphics[args], Infinity][[1]]
for more complicated cases you might need some more care, I don't know
exactly which features of GraphicsBox (which is basically undocumented)
are different to those of Graphics, there might e.g. be options that are
only available for GraphicsBox or need different settings...
hth,
albert