1

I'm trying to figure out how to print a message dialog without printing the whole notebook. FrontEndExecute[FrontEndToken["PrintDialog"]] displays the print window (just like selecting file -> print but it prints the whole notebook. I have also tried using FrontEndExecute[FrontEndToken["PrintSelectionDialog"]] but when the code is run the selected area becomes unselected.

I have solved part of the problem with the following

DialogInput[
  DialogNotebook[{Column[{Plot[Sin[x], {x, 0, 6 Pi}], 
      Row[{Button["print", 
         DialogReturn[
          FrontEndExecute[FrontEndToken["PrintDialog"]]]]}]}]}]];

This prints the entire window including the print button as shown.
print output
This is exactly what I am looking for but without the print button.
Any ideas much appreciated,
Christina

Christina
  • 199
  • 9
  • If you mean a message dialog that you code yourself. Consider creating a notebook on the fly that you format, size, and configure to operate as a message dialog. A bit of a heavy handed workaround but that should give you all the flexibility you need. Easier to answer if you give more a specific example and some code. – Jagra Aug 02 '12 at 19:45
  • Your question is not too well specified. I tried to provide a couple of general examples below, but if you will give more context for your problem I will try to be more specific myself. – Mr.Wizard Aug 02 '12 at 22:14
  • I appreciate the update. I tried to find a solution to print everything but the button but I could not. Hopefully someone with FrontEnd expertise will be able to. – Mr.Wizard Aug 05 '12 at 07:41

2 Answers2

4

Is this what you are looking for?

PrintMessage[expr_] := NotebookWrite[MessagesNotebook[],
       Cell[RawBoxes@ToBoxes[expr,StandardForm],"Output"]]
M.R.
  • 31,425
  • 8
  • 90
  • 281
  • Since Mr.Wizard's answer was accepted with the fact it does something different than yours, I think your answer isn't on topic. But I agree the question itself may be vague. – Kuba Apr 15 '15 at 07:22
  • True, but the key idea was "how to print a message dialog", which wasn't really answered. – M.R. Apr 15 '15 at 19:15
  • +1 Not sure what the OP was really looking for, but when I searched for writing to the Message window, this answer came up, and that's what I was looking for. – bobthechemist May 24 '15 at 12:25
1

It is not clear to me from your question how you want to use this operation. If you create a Button with this code you should be able to click the button to print a selected block of code.

Button["Print Selection",
  FrontEndTokenExecute @ "PrintSelectionDialog"
]

If you want to perform this operation programmatically you need to control the selection with e.g. SelectionMove.

(
 SelectionMove[EvaluationNotebook[], All, EvaluationCell];
 FrontEndTokenExecute @ "PrintSelectionDialog"
)

You can move the selection to a different Cell or Notebook if needed. In addition to the documentation for SelectionMove read: Manipulating Notebooks from the Kernel.

Mr.Wizard
  • 271,378
  • 34
  • 587
  • 1,371
  • Thanks for the help. In the end I created a button to execute NotebookPrint[CreateDocument[stuff to be printed]] – Christina Aug 16 '12 at 15:43
  • @Christina you're welcome; I'm sorry I didn't have something more specific for you, but I'm glad you found something that works for your application. – Mr.Wizard Aug 17 '12 at 00:53