run() and Macro Recorder ignoring calls to getBoolean()

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

run() and Macro Recorder ignoring calls to getBoolean()

Neil Fazel
I often invoke one .ijm macro from within another with help from the Macro Recorder. I first run the called macro interactively, then copy and paste into another macro whatever the Macro Recorder displays in the Recorder window. The Macro Recorder embeds arguments provided interactively by the user in the argument string it passes to the called macro. For example, if the called macro is MyMacro.ijm, and has two getNumber() calls in it to get arg1 and arg2, the Recorder shows this

   run("MyMacro", "arg1=8349 arg2=55");

But any calls to getBoolean() do not show up in the argument list, e.g. something like

   run("MyMacro", "arg1=8349 arg2=55 arg3=true");

is not generated. I tried inserting arg3=true by hand into the run() statement, but it was ignored by the called macro.

It would be nice if run() and Macro Recorder could handle Boolean arguments.

Thanks,
Neil

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

Re: run() and Macro Recorder ignoring calls to getBoolean()

Jan Eglinger
Hi Neil,

On 21.07.2014, 9:25 PM, Neil Fazel wrote:

> I often invoke one .ijm macro from within another with help from the Macro Recorder. I first run the called macro interactively, then copy and paste into another macro whatever the Macro Recorder displays in the Recorder window. The Macro Recorder embeds arguments provided interactively by the user in the argument string it passes to the called macro. For example, if the called macro is MyMacro.ijm, and has two getNumber() calls in it to get arg1 and arg2, the Recorder shows this
>
>     run("MyMacro", "arg1=8349 arg2=55");
>
> But any calls to getBoolean() do not show up in the argument list, e.g. something like
>
>     run("MyMacro", "arg1=8349 arg2=55 arg3=true");
>
> is not generated. I tried inserting arg3=true by hand into the run() statement, but it was ignored by the called macro.
>
> It would be nice if run() and Macro Recorder could handle Boolean arguments.

Boolean values (from dialog checkboxes) are recorded by the presence or
absence of the checkbox label in the argument string. Consider this macro:

     Dialog.create("Dialog asking for boolean options");
     Dialog.addCheckbox("Do_this", false);
     Dialog.addCheckbox("Do_that", true);
     Dialog.show();

     opt1 = Dialog.getCheckbox();
     opt2 = Dialog.getCheckbox();

     print("opt1 = " + opt1 + "; opt2 = " + opt2);

If you save this as "Boolean_Macro_Demo.ijm" anywhere in your /plugins/
directory, you can call it from the menu after restart, and the recorder
will record commands such as:

run("Boolean Macro Demo", "  do_that");
run("Boolean Macro Demo", "do_this");
run("Boolean Macro Demo", " ");

When both checkboxes are unchecked (false), just a space " " is recorded.

Hope that helps,
Jan

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

Re: run() and Macro Recorder ignoring calls to getBoolean()

Herbie-4
In reply to this post by Neil Fazel
Neil,

not perfectly sure if you speak about macros using Dialog-functions per
Dialog.create().

If so, Boolean parameters are passed in my case.
For example when I record one of my macros that asks for a choice per
pop-up menu, an integer number, a float number and finally a Boolean per
check-box, I get:

run(" ZonePlate", "style=Tapered support=128 oversampling=1.50 bipolar");

If the check-box "Bipolar" is left unchecked, I get:

run(" ZonePlate", "style=Tapered support=128 oversampling=1.50");

HTH

Herbie

::::::::::::::::::::::::::::::::::::
On 21.07.14 21:25, Neil Fazel wrote:

> I often invoke one .ijm macro from within another with help from the
> Macro Recorder. I first run the called macro interactively, then copy
> and paste into another macro whatever the Macro Recorder displays in
> the Recorder window. The Macro Recorder embeds arguments provided
> interactively by the user in the argument string it passes to the
> called macro. For example, if the called macro is MyMacro.ijm, and
> has two getNumber() calls in it to get arg1 and arg2, the Recorder
> shows this
>
> run("MyMacro", "arg1=8349 arg2=55");
>
> But any calls to getBoolean() do not show up in the argument list,
> e.g. something like
>
> run("MyMacro", "arg1=8349 arg2=55 arg3=true");
>
> is not generated. I tried inserting arg3=true by hand into the run()
> statement, but it was ignored by the called macro.
>
> It would be nice if run() and Macro Recorder could handle Boolean
> arguments.
>
> Thanks, Neil
>
> -- 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: run() and Macro Recorder ignoring calls to getBoolean()

Neil Fazel
In reply to this post by Neil Fazel
Hi Jan,

   Thanks for the response. I was referring to the dialog that pops up when you have a getBoolean() statement in the ImageJ macro code. It's ignored by the command recorder (Plugins -> Macros -> Record...) when it generates arguments for the run(...) statement. One would expect getBoolean() to get the same treatment from the recorder as getNumber() and getString(). It doesn't and I needed to remove calls to getBoolean() from my code in order to be able to invoke it using run(...).

Best regards,
Neil

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

Re: run() and Macro Recorder ignoring calls to getBoolean()

Neil Fazel
In reply to this post by Neil Fazel
Hi Herbie,

  Thanks for the reply. Yes, the macro recorder handles Dialog boolean options, but not a pop up created by getBoolean(). For example, I needed to replace

    includeSmallMargin=getBoolean("Include filter data close to the boundary (5 pixels and less)?");

with

    includeSmallMargin=(!getNumber("Include filter data close to the boundary (5 pixels and less)?", 0) == 0);


in order for the macro recorder to generate arguments for it.

Neil

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

Re: run() and Macro Recorder ignoring calls to getBoolean()

Jan Eglinger
In reply to this post by Neil Fazel
Hi Neil,

On 24.07.2014, 7:49 PM, Neil Fazel wrote:
>     Thanks for the response. I was referring to the dialog that pops up when you have a getBoolean() statement in the ImageJ macro code. It's ignored by the command recorder (Plugins -> Macros -> Record...) when it generates arguments for the run(...) statement. One would expect getBoolean() to get the same treatment from the recorder as getNumber() and getString(). It doesn't and I needed to remove calls to getBoolean() from my code in order to be able to invoke it using run(...).

You're right. I wasn't aware of the getBoolean() macro function. The
problem seems to be in the YesNoCancelDialog class that does not get
recorded, whereas the getNumber and getString functions use a
GenericDialog. I tested with this small Beanshell script:

     import ij.gui.YesNoCancelDialog;
     import ij.IJ;

     yncd = new YesNoCancelDialog(IJ.getInstance(), "YesNoCancelDialog",
"Really?");

     IJ.log("Cancelled: " + yncd.cancelPressed().toString());
     IJ.log("Yes: " + yncd.yesPressed().toString());


Cheers,
Jan

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

Re: run() and Macro Recorder ignoring calls to getBoolean()

Neil Fazel
In reply to this post by Neil Fazel
Hi Jan,

> The problem seems to be in the YesNoCancelDialog class that does not get recorded, whereas the getNumber and getString functions use a GenericDialog.

Thanks for this info. In all fairness, the ImageJ Macro Language Programmer’s Reference Guide v1.46d, has this to say under the entry for run():


  run("command"[, "options"])
  Executes an ImageJ menu command. The optional second argument contains
  values that are automatically entered into dialog boxes (must be GenericDialog or OpenDialog).


So this behavior (geBoolean() calls not getting recorded) is expected, since as you point out, getBoolean() calls use the YesNoCancelDialog class.

I use run() to invoke a macro inside a loop in a different macro. In this case, run() is VERY convenient to use because, unlike runMacro(), run() can be used to convert a macro that interacts with the user (by popping up many dialogs), into a macro that can be run without user interaction without any change to the macro. Also, unlike runMacro(), one doesn't have to construct an argument list in the calling macro, and then parse that in the called macro; the macro recorder automatically constructs the argument list. If run() could also handle YesNoCancelDialog, it would be even easier to convert interactive macros into non-interactive ones.

Best regards,
Neil

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html