On Jun 17, 2010, at 11:06 AM, Juanjo Vega wrote:
> Hi everybody,
>
> Is there any way to know if a "IJ.run()" command was completed or not?
>
> I mean, I'm executing "Plot Profile" when a button is pressed. As "Plot
> Profile" needs a selection, if no ROI was selected, ImageJ shows an
> error message and does nothing. So I would like to check if the command
> was successful and, if not, to select a tool.
>
> The idea is something like:
>
> IJ.run("Plot Profile");
> if(IJ.<SUCCESSFUL?>()){
> IJ.setTool(ToolBar.LINE);
> }
>
> I tried "IJ.escapePressed()", but it didn't work, as I expected.
>
> Sincerelly,
>
> Juanjo Vega.
What you can do is insure that conditions are right for the command to successfully complete. For the Plot Profile command, you can test to see if there is a line selection. Here is an example:
imp = IJ.getImage();
roi = imp.getRoi();
if (roi==null || !roi.isLine()) {
IJ.setTool(Toolbar.LINE);
IJ.error("Line selection required");
} else
IJ.run(imp, "Plot Profile","");
-wayne