6
$\begingroup$

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?

$\endgroup$
3
  • $\begingroup$ Can't test now but check ConvertToBitmapPacket and friends from 13451 $\endgroup$
    – Kuba
    Oct 11, 2015 at 21:47
  • $\begingroup$ @Kuba Thanks, but this Button["test", FrontEndTokenExecute["ConvertToBitmapPacket"]] did not work on a selected Cell. $\endgroup$
    – iLie
    Oct 11, 2015 at 22:00
  • $\begingroup$ 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. $\endgroup$
    – Kuba
    Oct 12, 2015 at 6:08

1 Answer 1

4
$\begingroup$

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

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.