Disable the cancel button on a macro dialog box

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Disable the cancel button on a macro dialog box

mattjackson
I have a dialog box within my macro. There's a lot of interaction here (over the course of hours), and just every so often, I accidentally hit the cancel button, abort the macro, and lose all the data.

So, does anyone know of a way to disable the cancel button or retrieve the cancel call within the macro and do some if structure to avoid aborting the program?

Or, is there a way to store certain arrays even if the cancel button is hit? That is, instead of purging the data and losing it, can I program the macro to auto-write in any case the macro is terminated?

Thanks so much,
Matt
Reply | Threaded
Open this post in threaded view
|

Re: Disable the cancel button on a macro dialog box

Brandon Hurr
Matt,

I've had similar issues when looping through many images in a folder where
user input is required. The data would be output to a results table and
only saved to a file when done looping. I quickly learned that I would
forget to save the file when it errored, or the error was so critical it
would cause a crash and I would lose the table.

Essentially, I wrote the file out at the end of every loop so I wouldn't
lose more than a single file's data. I thought this would cause a
performance hit, but in my case the hit was negligible.

HTH,

Brandon

On Wed, Mar 18, 2015 at 8:35 AM, mattjackson <[hidden email]> wrote:

> I have a dialog box within my macro. There's a lot of interaction here
> (over
> the course of hours), and just every so often, I accidentally hit the
> cancel
> button, abort the macro, and lose all the data.
>
> So, does anyone know of a way to disable the cancel button or retrieve the
> cancel call within the macro and do some if structure to avoid aborting the
> program?
>
> Or, is there a way to store certain arrays even if the cancel button is
> hit?
> That is, instead of purging the data and losing it, can I program the macro
> to auto-write in any case the macro is terminated?
>
> Thanks so much,
> Matt
>
>
>
> --
> View this message in context:
> http://imagej.1557.x6.nabble.com/Disable-the-cancel-button-on-a-macro-dialog-box-tp5012041.html
> Sent from the ImageJ mailing list archive at Nabble.com.
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Disable the cancel button on a macro dialog box

mattjackson
I'll have to play with this. Appending data won't really work because I sometimes go back and forth through the loop (via slider bar). I think I can write out a trick to write then delete the previous file without deleting work from a previous session, otherwise I'd end up with tens of thousands of text files.

Thanks Brandon,
M
Reply | Threaded
Open this post in threaded view
|

Re: Disable the cancel button on a macro dialog box

mattjackson
That turned out to be relatively simple. I'm sharing just in case someone else runs into the same problem:
------------------------------------------------------------------------------------------------------------------

GetDateAndTime(year, month, dayOfWeek, dayOfMonth, hour, minute, second, msec);
TimeStamp=MonthNames[month]+"-"+dayOfMonth+"-"+year+"_"+hour+"-"+minute+"-"+second;
OutputCALL = dir + "\\Calls_"+TimeStamp+".txt";

//Output the user's phenotype calls
f = File.open(OutputCALL);
print(f,"ROIIndex Calls");
for(j=0;j<Nroi;j++) {getDateAndTime(year, month, dayOfWeek, dayOfMonth, hour, minute, second, msec);
       print(f,j+" "+Cell[j]);
}
File.close(f);
       
if(OldOutput!=0){
File.delete(OldOutput);
}
       
OldOutput=OutputCALL;