Re: Auto-Animate Button ?
- To: mathgroup at smc.vnet.net
- Subject: [mg8377] Re: Auto-Animate Button ?
- From: "Theodore W. Gray" <theodore>
- Date: Tue, 26 Aug 1997 20:41:12 -0400
- Organization: Wolfram Research, Inc.
- Sender: owner-wri-mathgroup at wolfram.com
> This button create new notebook and draw graphics. > But SelectionMove is evaluated before end of draw graphics. The reason is that the SelectionEvaluate is executed asynchronously. This is a very good thing, most of the time! In your case, however, what happens is that SelectionEvaluate initiates the evaluation in the kernel, and then the front end continues processing the button function. You want the remainder of the commands to be executed AFTER the evaluation finishes. The easiest way to do this is to make them a part of the command that you evalate in the kernel. For example, evaluate the following definition somewhere: StartAnimation[t___] := ( SelectionMove[EvaluationNotebook[], All, GeneratedCell]; FrontEndExecute[{FrontEndToken[EvaluationNotebook[], "SelectionCloseAllGroups"]}]; SelectionAnimate[EvaluationNotebook[], t]; ) and then modify your button function to read: Cell[BoxData[ ButtonBox["Anim", ButtonEvaluator->Automatic, ButtonFunction:>{Set[nb,NotebookCreate[]]; NotebookWrite[nb, "Do[Plot[Sin[x+t],{x,0,2 Pi}],{t,0,2 Pi}]; StartAnimation[]"];}, ButtonStyle->"Evaluate"]], "Input", Active->True] (My way of selecting all the output cells is somewhat more reliable than yours. It guarantees that the correct group is selected even if the user has moved the selection point manually during the evaluation. It also automatically closes the cell group, so only the first graphic is visible.) You can read about many of these issues in my new book, The Beginner's Guide to Mathematica V3, available at: http://www.mathware.com/BeginnersGuide Theodore W. Gray