1
$\begingroup$

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

$\endgroup$
3
  • $\begingroup$ 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. $\endgroup$
    – Jagra
    Commented Aug 2, 2012 at 19:45
  • $\begingroup$ 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. $\endgroup$
    – Mr.Wizard
    Commented Aug 2, 2012 at 22:14
  • $\begingroup$ 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. $\endgroup$
    – Mr.Wizard
    Commented Aug 5, 2012 at 7:41

2 Answers 2

1
$\begingroup$

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.

$\endgroup$
2
  • $\begingroup$ Thanks for the help. In the end I created a button to execute NotebookPrint[CreateDocument[stuff to be printed]] $\endgroup$
    – Christina
    Commented Aug 16, 2012 at 15:43
  • $\begingroup$ @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. $\endgroup$
    – Mr.Wizard
    Commented Aug 17, 2012 at 0:53
4
$\begingroup$

Is this what you are looking for?

PrintMessage[expr_] := NotebookWrite[MessagesNotebook[],
       Cell[RawBoxes@ToBoxes[expr,StandardForm],"Output"]]
$\endgroup$
3
  • $\begingroup$ 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. $\endgroup$
    – Kuba
    Commented Apr 15, 2015 at 7:22
  • $\begingroup$ True, but the key idea was "how to print a message dialog", which wasn't really answered. $\endgroup$
    – M.R.
    Commented Apr 15, 2015 at 19:15
  • $\begingroup$ +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. $\endgroup$ Commented May 24, 2015 at 12:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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