Hello again,
I will just copy a simple code below to describe what I am getting.
The output in the first notebook is a = a; b = b ; ...
What I want is to execute this like a routine, so nb2 should be
evaluated before the Print[].
I understand that my program may need some improvement and I will
work on that, but I really want to know how to solve the problem I have
just described.
Thanks again
Maria Cristina
++++++++++++++++++++++++++++++++++ notebooks ++++++++++++++++++++++++
This is the former notebook ;
Do[
{
c = 3,
nb2 = NotebookOpen["tt1.nb"],
SelectionMove[nb2, All, Notebook],
Print["k main ", k],
SelectionEvaluate[nb2],
Print["a = ", a],
Print["b = ", b],
Print["ac = ", ac],
Print["bc = ", bc],
},
{k, 1, 1}]
tt1.nb :
Print["k = ",k," nb2"]
a=k+2
ac=c+2
nb3=NotebookOpen["tt2.nb"]
SelectionMove[nb3,All,Notebook]
SelectionEvaluate[nb3]
saida=ToString[k]
saida=StringInsert[saida,".tt1.sai",StringLength[saida]+1]
NotebookSave[nb2,saida]
tt2.nb
Print["k = ",k," tt2"]
b=k+10
bc=c+10
saida=ToString[k]
saida=StringInsert[saida,".tt2.sai",StringLength[saida]+1]
NotebookSave[nb3,saida]
David Annetts wrote:
>Hi Maria,
>
>
>
>> I thank both Dave and Luc very much, I manage to go one
>>step further.
>>
>> I have tryed SelectionEvaluation before, but I could not
>>identify the notebook properly. Now after you told me I tryed
>>with NotebookOpen and it couldn't find the file ($Failed). I
>>had to include my working directory in the preferences, and
>>now it works.
>>
>> I prepare a very simple test, just a notebook calling a
>>second nb which calls a third one. It works perfectly,
>>opened and executed each notebook without a problem.
>>
>> Then I put these callings inside a loop (Do) which would
>>just print the loop iteration number.
>>
>> Now I come to another problem. All the expressions inside
>>the loop are executed and only afterwards the execution of
>>the second notebook is performed. Only after that the
>>execution of notebook 3 is evaluated.
>>
>> This is not what I need. I need that the calling of the
>>notebook evalutaion is treated like if it were a routine,
>>the program is deviated to the second notebook and after
>>evaluating it completely it would come back to the following
>>command inside the loop.
>>
>> Can anyone give me another advice ?
>>
>>
>
>Just to ensure I understand you, you have
>
> nb01 -> nb02 -> nb03
>
>Which works. However, you need
>
> nb01 -> Do[nb02, {iter}]] -> nb03.
>
>To me (and assuming I've got it right), this sounds like a perfect
>application for a package. The minimum you need to do is save the notebook
>as a package (Save as special -> package). Commands in the package (it's
>difficult to tell exactly what you've done) can then be called as part of a
>loop, much as you would call any of the standard packages.
>
>Hope that helps,
>
>Dave.
>
>
--
Profa Maria Cristina Tavares
Faculdade de Engenharia Elétrica e de Computação
UNICAMP / FEEC / DSCE
CP 6101 - CEP 13083-970
tel : (19) 3788 3738
fax : (19) 3289 1395
http://www.dsce.fee.unicamp.br/~cristina
--------------070400090109010604090601
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Hello again,<br>
<br>
&nbsp;&nbsp;&nbsp; I will just copy a simple code below to describe what I am getting.
The output in the first notebook is a = a; b = b ; ...<br>
<br>
&nbsp;&nbsp;&nbsp; What I want is to execute this like a routine, so nb2 should be
evaluated before the Print[].<br>
<br>
&nbsp;&nbsp;&nbsp; I understand that my program may need some improvement and I will
work on that, but I really want to know how to solve the problem I have
just described.<br>
<br>
&nbsp;&nbsp;&nbsp; Thanks again<br>
<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; Maria Cristina<br>
++++++++++++++++++++++++++++++++++&nbsp;&nbsp; notebooks ++++++++++++++++++++++++<br>
<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; This is the former notebook ;<br>
Do[<br>
&nbsp; {<br>
&nbsp;&nbsp; &nbsp; c = 3,<br>
&nbsp;&nbsp;&nbsp;&nbsp; nb2 = NotebookOpen["tt1.nb"],<br>
&nbsp;&nbsp;&nbsp;&nbsp; SelectionMove[nb2, All, Notebook],<br>
&nbsp;&nbsp;&nbsp;&nbsp; Print["k main ", k],<br>
&nbsp;&nbsp;&nbsp;&nbsp; SelectionEvaluate[nb2],<br>
&nbsp;&nbsp;&nbsp;&nbsp; Print["a = ", a],<br>
&nbsp;&nbsp;&nbsp;&nbsp; Print["b = ", b],<br>
&nbsp;&nbsp;&nbsp;&nbsp; Print["ac = ", ac],<br>
&nbsp;&nbsp; &nbsp; Print["bc = ", bc],<br>
&nbsp;&nbsp;&nbsp; },<br>
&nbsp; {k, 1, 1}]<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; tt1.nb :<br>
Print["k = ",k," nb2"]<br>
a=k+2<br>
ac=c+2<br>
&nbsp;nb3=NotebookOpen["tt2.nb"]<br>
&nbsp;SelectionMove[nb3,All,Notebook]<br>
&nbsp;SelectionEvaluate[nb3]<br>
saida=ToString[k]<br>
saida=StringInsert[saida,".tt1.sai",StringLength[saida]+1]<br>
NotebookSave[nb2,saida]<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; tt2.nb<br>
<br>
Print["k = ",k," tt2"]<br>
b=k+10<br>
bc=c+10<br>
saida=ToString[k]<br>
saida=StringInsert[saida,".tt2.sai",StringLength[saida]+1]<br>
NotebookSave[nb3,saida]<br>
<br>
David Annetts wrote:<br>
<blockquote cite="mid20050916044831.D106BBC36 at mfep9.connect.com.au"
type="cite">
<pre wrap="">Hi Maria,
</pre>
<blockquote type="cite">
<pre wrap=""> I thank both Dave and Luc very much, I manage to go one
step further.
I have tryed SelectionEvaluation before, but I could not
identify the notebook properly. Now after you told me I tryed
with NotebookOpen and it couldn't find the file ($Failed). I
had to include my working directory in the preferences, and
now it works.
I prepare a very simple test, just a notebook calling a
second nb which calls a third one. It works perfectly,
opened and executed each notebook without a problem.
Then I put these callings inside a loop (Do) which would
just print the loop iteration number.
Now I come to another problem. All the expressions inside
the loop are executed and only afterwards the execution of
the second notebook is performed. Only after that the
execution of notebook 3 is evaluated.
This is not what I need. I need that the calling of the
notebook evalutaion is treated like if it were a routine,
the program is deviated to the second notebook and after
evaluating it completely it would come back to the following
command inside the loop.
Can anyone give me another advice ?
</pre>
</blockquote>
<pre wrap=""><!---->
Just to ensure I understand you, you have
nb01 -&gt; nb02 -&gt; nb03
Which works. However, you need
nb01 -&gt; Do[nb02, {iter}]] -&gt; nb03.
To me (and assuming I've got it right), this sounds like a perfect
application for a package. The minimum you need to do is save the notebook
as a package (Save as special -&gt; package). Commands in the package (it's
difficult to tell exactly what you've done) can then be called as part of a
loop, much as you would call any of the standard packages.
Hope that helps,
Dave.
</pre>
</blockquote>
<br>
<br>
<pre class="moz-signature" cols="72">--
Profa Maria Cristina Tavares
Faculdade de Engenharia El&eacute;trica e de Computa&ccedil;&atilde;o
UNICAMP / FEEC / DSCE
CP 6101 - CEP 13083-970
tel : (19) 3788 3738
fax : (19) 3289 1395
<a class="moz-txt-link-freetext" href="http://www.dsce.fee.unicamp.br/~cristina&quot;>http://www.dsce.fee.unicamp.br/~cristina</a></pre>
</body>
</html>
--------------070400090109010604090601--