Bring front a graph and do some specific action

Dear All,
I would like to make a batch processing with a specific action for set of graphs. For the same, I made following code. It first brings a specified graph front, then calls a macro for specified action and, last hide the graph.

There is some issues which could not be figured out by me. It just work fine for only first graph. Thereafter, although graph comes front and then hide properly, specified action did not took place. Any help pls.

My aim is to set the marker size range from standard 0 to 10 to say 0 to 5 or any custom value.

An Igor file attached for model data with 3 graphs.

Best,
Maniraj

Macro ChangeWeightMarkerSize(sn,en)
variable sn,en  //start and end graph-numbers
variable i=sn
Silent 1; PauseUpdate
    do
        BringFrontSpecificGraph(i)
       
        ActionOnFrontGraph()
       
        HideSpecificGraph(i)
       
    i=i+1
    while (i<=en)
    beep
    beep
    beep
End


Macro ActionOnFrontGraph()
String w="",cmd="",wn1="",wn2=""
Silent 1; PauseUpdate
       
        cmd=""
        wn1= WaveList("*_energy", "", "WIN:")
        wn2= WaveList("*_w", "", "WIN:")
        sprintf cmd,"ModifyGraph zmrkSize(%s)={%s,*,*,1,5}",wn1,wn2
        //Print cmd
        Execute/P/Q cmd
End


Macro BringFrontSpecificGraph(num)
variable num
String w="",cmd=""
Silent 1; PauseUpdate
        w="Graph"+num2str(num)
        cmd=""
        sprintf cmd, "DoWindow/F %s", w
        Execute/P/Q cmd
End


Macro HideSpecificGraph(num)
variable num
String w="",cmd=""
Silent 1; PauseUpdate
        w="Graph"+num2str(num)
        cmd=""
        sprintf cmd, "DoWindow/HIDE=1%s", w
        Execute/P/Q cmd
End

 
test_3.pxp
I have some general suggestions first.

* Write using Functions not Macros.
* Avoid using Execute for the commands. Just run the commands directly.

Specific to your problem, I believe that once you eliminate all of the Execute statements in favor of the commands themselves, your problem will disappear. Why? Essentially because an Execute command is put "in a queue", has to wait its turn to be completed, and in your case never gets completed at the right time.

--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAH
I was stuck to use function. For example, how to put Dowindow/F XXX in function. Could you please give me example.
I tried following code as a first step. There is no error but, no action as well.
Function ChangeWeightMarkerSize(sn,en)
variable sn,en
variable i=sn
String w=""
    for(i=sn;i<=en;i=i+1)  
        w="Graph"+num2str(i)
        //print w
        DoWindow/F w                                   
    endfor                                             
   
    beep
    beep
    beep
End

Am I making any mistake ?
Best,
Maniraj
You need to convert the string w to an object reference (in this case a window reference) using $w. The use of $ is one of the most confusing things in Igor.

DoWindow/F $w
My guess is that the problem is with the use of Execute/P. The addition of the P flag causes Igor to put the command in a queue and do it later when it's not doing other work. I'm not sure how that would interact with a Macro; in a Function is will put off execution of the command until after the function finishes. In any case, your intent is to have it execute immediately, so remove /P.

And, yes, use Functions.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
Thanks a lot for all suggestions.
I followed suggestions and make it to work in function.
Thanks.