7

I've seen good discussions about the full list of FrontEndTokens.

But I could not figure out how to find a specific FrontEndToken for a menu item. I'd like to make a Button that does what Cell ► Convert To ► Bitmap menu item does. I have not seen the word "Bitmap" in the list and not sure if Button will work on a selected Cell. Any ideas?

Alexey Popkov
  • 61,809
  • 7
  • 149
  • 368
iLie
  • 83
  • 5
  • Can't test now but check ConvertToBitmapPacket and friends from 13451 – Kuba Oct 11 '15 at 21:47
  • @Kuba Thanks, but this Button["test", FrontEndTokenExecute["ConvertToBitmapPacket"]] did not work on a selected Cell. – iLie Oct 11 '15 at 22:00
  • Those are not tokens but functions which usually work like this: FrontEndExecute @ ConvertToBitmapPacket [ object] but the problem is, you never now since they are undocumented and sometimes wrong argument may cause mma crash. – Kuba Oct 12 '15 at 06:08

1 Answers1

5

You need the FrontEndToken "SelectionConvert". An example of use:

Plot[Sin[x], {x, -Pi, Pi}]
SelectionMove[EvaluationNotebook[], Previous, CellContents];
FrontEndExecute[FrontEndToken[EvaluationNotebook[], "SelectionConvert", "Bitmap"]];

screenshot

However please beware that FrontEnd's conversion to Bitmap command looses the alpha channel. As a workaround you could implement your own version of this token with support of the alpha channel, for example as follows:

Plot[Sin[x], {x, -Pi, Pi}]
nb = EvaluationNotebook[];
SelectionMove[nb, Previous, CellContents];
NotebookWrite[nb, 
 ToBoxes@Rasterize[Style[RawBoxes@NotebookRead[nb], Options[nb]], Background -> None]]
SetOptions[nb, Background -> Green]

screenchot

Alexey Popkov
  • 61,809
  • 7
  • 149
  • 368