Successful IJ.run()?

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

Successful IJ.run()?

Juanjo Vega
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.
Reply | Threaded
Open this post in threaded view
|

Re: Successful IJ.run()?

Rasband, Wayne (NIH/NIMH) [E]
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
Reply | Threaded
Open this post in threaded view
|

Re: Successful IJ.run()?

Juanjo Vega
On Fri, 2010-06-18 at 00:21 -0400, Rasband, Wayne (NIH/NIMH) [E] wrote:

> 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","");

Hi,

That's a good idea, I didn't think that way. Thank you very much :)

Sincerelly,

Juanjo.

>
> -wayne