Bring front a graph and do some specific action
maniraj
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
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
* 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
October 27, 2016 at 08:13 am - Permalink
I tried following code as a first step. There is no error but, no action as well.
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
October 27, 2016 at 08:41 am - Permalink
DoWindow/F $w
October 27, 2016 at 09:22 am - Permalink
And, yes, use Functions.
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
October 27, 2016 at 10:35 am - Permalink
I followed suggestions and make it to work in function.
Thanks.
October 27, 2016 at 11:56 am - Permalink