FrontEnd-Kernel Synching, was: How to animate?
- To: mathgroup at smc.vnet.net
- Subject: [mg38551] FrontEnd-Kernel Synching, was: [mg38509] How to animate?
- From: Omega Consulting <info at omegaconsultinggroup.com>
- Date: Wed, 25 Dec 2002 03:13:01 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
At 10:40 PM 12/20/2002, David Park wrote: >DoShow /@ frames1; >SelectionMove[EvaluationNotebook[], All, GeneratedCell] >FrontEndTokenExecute["OpenCloseGroup"]; Pause[0.01]; >FrontEndExecute[{FrontEnd`SelectionAnimate[200, AnimationDisplayTime -> 0.1, > AnimationDirection -> Forward]}] > >The Pause command was included to guarantee that the cell group is closed >before the animation starts. However I find that there is a bug in Pause in >that it always pauses for 1 second even though it should handle smaller time >intervals. > >David Park Just a side note here: This is related to a problem I often have. Some commands (such as FrontEndExecute) only instruct the frontend to do an operation. The kernel does not wait until the frontend has finished. Here's an example: In[]:= nb=NotebookCreate[]; In[]:= fname = "test.nb"; The ReadList acts before NotebookSave is finished. If the file didn't exist previously, the ReadList fails even though the file is created. In[]:= NotebookSave[nb, fname]; ReadList[fname, Record] ReadList::nffil: File not found during \[LeftSkeleton]1\[RightSkeleton]. Out[]= $Failed You can try to synchronize with Pause, except that it is limited to an integer number of seconds (as David notes) and you can't be certain that your Pause will always be long enough. The best trick I've come up with is to execute a command that requires both frontend and kernel activity. Like a frontend command that returns a kernel result, such as Notebooks[]. The kernel will wait until the frontend sends the list of NotebookObjects. And the frontend does not send this list until it has completed all previous actions. In[]:= DeleteFile[fname]; In[]:= NotebookSave[nb, fname]; Notebooks[]; ReadList[fname, Record]//Length Out[]= 62 I find this much more reliable than Pause. -------------------------------------------------------------- Omega Consulting "The final answer to your Mathematica needs" http://omegaconsultinggroup.com