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

MathGroup Archive 2010

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

Search the Archive

Re: Directing formatted output to different notebooks

  • To: mathgroup at smc.vnet.net
  • Subject: [mg109445] Re: Directing formatted output to different notebooks
  • From: Albert Retey <awnl at gmx-topmail.de>
  • Date: Tue, 27 Apr 2010 07:41:17 -0400 (EDT)
  • References: <hr65rt$jqh$1@smc.vnet.net>

Am 27.04.2010 10:05, schrieb Paul Howland:
> Hello.
> 
> I am dynamically creating a notebook from another notebook.
> 
> I would like to be able to display a formatted table in the
> dynamically created notebook (e.g. equivalent of
> Print[TableForm[...]]]).  Ideally, I would like to be able to direct
> the output of the Print[] statement to the new notebook, rather than
> the one that is executing the code.
> 
> However, SetSelectedNotebook[] doesn't appear to do this.
> 
> Using NotebookWrite does allow me to write to the new notebook, but
> requires low-level manipulation of Boxes, etc.  It doesn't seem able
> to take higher level formatting commands and direct these to the
> notebook.
> 
> Is it possible to do something like NotebookWrite[nb, TableForm[...]]
> or to somehow re-direct normal Print output to the new notebook?  I'm
> getting lost in GridBoxes, etc at the moment and there must be a
> simpler way!

If you use ToBoxes and define something like this:

printtonb[nb_, expr_] := (
  SelectionMove[nb, After, Cell];
  NotebookWrite[nb, Cell[BoxData[ToBoxes[expr]], "Print"]]
  )

the printtonb will behave a lot like a Print redirected to the other
notebook:

nb = CreateDocument[];
printtonb[nb, TableForm[RandomReal[{0, 1}, {3, 3}]]]
printtonb[nb, TableForm[RandomReal[{0, 1}, {3, 3}]]]

you might also want to consider "Output" as CellStyle instead of "Print"...

hth,

albert


  • Prev by Date: Why Return[] does not work?
  • Next by Date: Re: how uncouple dynamic objects?
  • Previous by thread: Directing formatted output to different notebooks
  • Next by thread: Re: Directing formatted output to different notebooks