Group Abstract Group Abstract

Message Boards Message Boards

0
|
2.3K Views
|
8 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Write a generated image to another notebook?

Posted 11 months ago

I'm learning the NotebookWrite[] interface and have hit a wall on inserting images.

What I've done is a script that generates a map that I then want to insert the image that results from the code into the daily notebook, but everything I've tried thus far instead inserts the raw code, not the map image.

POSTED BY: Steven Buehler
8 Replies
Posted 11 months ago

Your code did not insert the image, only the "New Content" portion.

POSTED BY: Steven Buehler
nb = CreateDocument[];
(*NotebookWrite[nb, Cell["New content", "Subsection"]];*)
ExampleData[{"TestImage", "JellyBeans"}] // 
 NotebookWrite[nb,
   Cell[BoxData[MakeBoxes[#, StandardForm]], "Output"]] &

You have to convert the expression you want to display to boxes. MakeBoxes[] is HoldAllComplete, so you have to evaluate the code that produces the image (even if the "code" is simply a variable) before passing the resulting image to MakeBoxes. You can use With[] instead of a pure function, if you prefer.

When trying to figure this stuff, the menu command Cell > Show Expression can be helpful, in case you hadn't run across it yet. You can use it to see how the system creates the cells you type and compute and mimic it.

POSTED BY: Michael Rogers
Posted 11 months ago
POSTED BY: Steven Buehler
POSTED BY: Michael Rogers
Posted 11 months ago

Okay, the following worked, although the graphic size was rather small (I'll need to figure out the sizing). I guess I need to wrap larger code in Module or something...

nb = CreateDocument[];
GeoGraphics[GeoMarker[Here]] // 
 NotebookWrite[nb, 
   Cell[BoxData[MakeBoxes[#, StandardForm]], "Output"]] &
POSTED BY: Steven Buehler

Great. For me, the created notebook has an image a few pixels larger than the standard output of GeoGraphics[GeoMarker[Here]]. In any case, there's the ImageSize option you can use to control the size of the output image.

POSTED BY: Michael Rogers
Posted 11 months ago
POSTED BY: Steven Buehler

The code Michael provided works perfectly for me on V14.1

POSTED BY: Ahmed Elbanna
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard