Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1999
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1999

[Date Index] [Thread Index] [Author Index]

Search the Archive

Manipulating notebooks from the kernel: Order in which commands are executed?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg16142] Manipulating notebooks from the kernel: Order in which commands are executed?
  • From: r.lawrence at worldnet.att.net (Robert Lawrence)
  • Date: Sat, 27 Feb 1999 03:23:09 -0500
  • Organization: AT&T WorldNet Services
  • Sender: owner-wri-mathgroup at wolfram.com

I created a button with the following ButtonFunction:

	NotebookLocate["tagName"];
	SelectionEvaluateCreateCell[SelectedNotebook[]];

This properly found the cell in the active notebook with the tag
"tagName", evaluated that cell, and created a new cell containing the
result of the evaluation, with the current selection being immediately
after the new cell .

Now I added a line to the ButtonFunction, so that it read:

	NotebookLocate["tagName"];
	SelectionEvaluateCreateCell[SelectedNotebook[];
	SelectionMove[SelectedNotebook[], Previous,Cell];

But instead of moving the current selection to the new cell as I had
expected, this moved the current selection to the cell immediately
before the new cell (i.e., the cell with the tag "tagName").  This
behavior gave me the impression that, at the time SelectionMove was
executed, the new cell created by SelectionEvaluateCreateCell had not
yet been recognized in some sense.

Something similar seems to occur in the following example, which is
based upon an extension of some code posted by Jean-Marie Thomas in
December 1997 (and which I came across in seeking a solution for the
above problem):

Here is Thomas's code:

thisNotebook=SelectedNotebook[];
defNotebook=
  "notebook A.nb";(*give the correct path with Input/get file path*)
NotebookLocate[{defNotebook,"foo3 definition"}];
data=NotebookRead[defNotebook];
SetSelectedNotebook[thisNotebook];
NotebookWrite[thisNotebook,data];
SelectionMove[thisNotebook,Previous,Cell];
SelectionEvaluate[thisNotebook];

This code copies the cell in defNotebook with tag "foo3 definition",
and pastes it into thisNotebook.  The code then evaluates the
newly-pasted cell and leaves the current selection immediately after
the newly-pasted cell (or immediately after the cell containing the
output of the evaluation, if output is displayed).  All of this works
as expected.

However, I tried adding two lines to Thomas's code, so that it read as
follows:

thisNotebook=SelectedNotebook[];
defNotebook=
  "notebook A.nb";(*give the correct path with Input/get file path*)
NotebookLocate[{defNotebook,"foo3 definition"}];
data=NotebookRead[defNotebook];
SetSelectedNotebook[thisNotebook];
NotebookWrite[thisNotebook,data];
SelectionMove[thisNotebook,Previous,Cell];
SelectionEvaluate[thisNotebook];
SelectionMove[thisNotebook,Previous,Cell];
NotebookDelete[thisNotebook];

The added lines are designed to delete the pasted cell after it has
been evaluated.  Surprisingly, however, this augmented code merely
deletes the pasted cell without ever evaluating it, giving the
impression that the NotebookDelete command is somehow executed before
the SelectionEvaluate command has been executed.

I would be grateful for any insights into these apparent anomalies.

Robert Lawrence


  • Prev by Date: Re: bitmaps disappearing
  • Next by Date: Using Utilities`Notation` in a package
  • Previous by thread: Help!! - Problems printing to Adobe Acrobat
  • Next by thread: Using Utilities`Notation` in a package