Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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

share|improve this question
    
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 2 '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 2 '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 5 '12 at 7:41

1 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer
    
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 0:53

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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