Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Extracting graphics from notebook

  • To: mathgroup at smc.vnet.net
  • Subject: [mg115508] Re: Extracting graphics from notebook
  • From: Albert Retey <awnl at gmx-topmail.de>
  • Date: Thu, 13 Jan 2011 03:25:49 -0500 (EST)
  • References: <iggq6a$4gt$1@smc.vnet.net> <ighgl8$ajk$1@smc.vnet.net> <igis8v$pnn$1@smc.vnet.net>

Am 12.01.2011 01:22, schrieb Chris Degnen:
> 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]]
> 
> 
... and I think it might well be the better approach :-)

albert


  • Prev by Date: Caution on BibTex references with Mathematica
  • Next by Date: Re: FindInstance does not abort with TimeConstrained
  • Previous by thread: Re: Extracting graphics from notebook
  • Next by thread: Problems "Import"ing with Mathematica running Unbuntu