FAQ
overflow

Great Answers to
Questions About Everything

QUESTION

I have a notebook where evaluation of a certain cell produced hundreds of adjacent output cells using Print. I need to create a list containing all expressions from those output cells as elements, and assign the list to a variable without re-running the evaluation.

Could you suggest a way to automate this process to avoid manually copying all expressions?

{ asked by Vladimir Reshetnikov }

ANSWER

The following seems to work, however I think it's not general enough:

At a clean nb, enter:

For[i = 0, i < 4, i++, Print[{i, {33, i}}]]
For[i = 0, i < 4, i++, Print[Graphics[Circle[], ImageSize -> 20]]]

Mathematica graphics

And then retrieve the Print[ ] output as:

c = Cases[NotebookRead /@ Cells[GeneratedCell -> True], Cell[___, "Print", ___]];
ToExpression /@ Cases[c, BoxData[__], {2}]

Mathematica graphics

{ answered by belisarius }
Tweet