Re: Extracting graphics from notebook
- To: mathgroup at smc.vnet.net
- Subject: [mg115466] Re: Extracting graphics from notebook
- From: Chris Degnen <degnen at cwgsy.net>
- Date: Tue, 11 Jan 2011 19:22:54 -0500 (EST)
- References: <iggq6a$4gt$1@smc.vnet.net> <ighgl8$ajk$1@smc.vnet.net>
On Jan 11, 11:58 am, Albert Retey <a... at gmx-topmail.de> wrote: > 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 Thanks Albert, I also found this works:- content = NotebookRead[nb2]; ToExpression[First[content]]