Login  Register

Re: calling macros or functions from within a macro

Posted by Wayne Rasband-2 on Dec 16, 2020; 5:15pm
URL: http://imagej.273.s1.nabble.com/calling-macros-or-functions-from-within-a-macro-tp5024276p5024279.html

> On Dec 16, 2020, at 9:44 AM, Cammer, Michael <[hidden email]> wrote:
>
> I would like to use the pull down menu to run a macro that is in the same text file or a function in the same file.  runMacro() requires a file on disk and trying to call a function I defined returns an error message.

The following macro code, when saved as a file and installed using Plugins>Macros>Install, creates an image popup menu that with a “My Function” command that calls the function myFunction().

-wayne

  var pmCmds = newMenu("Popup Menu",
      newArray("My Function","Fire","Invert LUT"));

  macro "Popup Menu" {
     cmd = getArgument();
     if (cmd=="My Function")
        myFunction();
      else
        run(cmd);
  }

  function myFunction() {
     print("successful");
  }


> For instance, based on https://imagej.nih.gov/ij/macros/CustomPopupMenu.txt, I tried the following with my function testPulldownMenu().  The other commands in the list are mostly macros in the same file.  And the B&C commands works fine.
>
>
> Is there a way to call my own functions or macros?  Any help greatly appreciated.
>
>
> var pmCmds = newMenu("Popup Menu",
>       newArray("testPulldownMenu", "Prepare image for markup", "Mark Distal", "Mark Nucleus", "Add Line Segment", "Grays LUT", "Color LUT",
>       "Brightness/Contrast..."));
>
>  macro "Popup Menu" {
>      cmd = getArgument();
>      run(cmd);
>      //runMacro(cmd);
>  }
>
> function testPulldownMenu() {
> print("successful");
> }

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