Installing macros for easy access

When you write a macro and save it to a file, you can run it easily by navigating to Plugins | Macros | Run..., and then select the file that contains it. However, if you are going to run a macro several times, this can get tiresome. Fortunately, you can install a set of macros for easy access by navigating to Plugins | Macros | Install.... In order to use this command, we first have to give our macro a name. This is done in the following way:

macro "Test macro" {
// The macro code goes inside the curly braces. Nothing else changes.
}

You can have several macros in a file using this naming convention. Variables can be shared between different macros if they are defined outside the macro blocks and are preceded by the var keyword. Functions defined outside a particular macro block can be accessed by any macro in the file.

We will further explain these concepts with the following example:

var common = "I'm a common variable";
// This function can be called by either macro
functionmyprint(s) {
print(s);
}
macro "Macro 1" {
  macro1 = "I'm a variable that belongs to macro1";
  myprint(common); // Accesses a common variable using a common function, that's OK
  myprint(macro1);
}
macro "Macro 2" {
    macro2 = macro1; // Will show an error message
}

Save this macro to a file by navigating to Plugins | Macros | Install.... Select the file you just saved and apparently nothing will happen, but the macros you have created are now accessible directly by navigating to the Plugins | Macros menu, below the divider bar. If you install another file containing macros, the previous ones will be replaced.

You can also assign key shortcuts to your macros. Simply add the key you want to use between the square brackets after the macro name, as follows:

macro "Macro 3 [m]" { … }

If you install your macros and restart ImageJ, you will see that they are no longer there. You need to install them again to be able to access them quickly. If you want to have them accessible when you restart, you will need to add them to the ImageJ/macros/StartupMacros.txt file. This file is loaded every time ImageJ starts. You can browse for it or navigate to Plugins | Macros | StartupMacros.... This will open an editor window that will allow you to modify that file.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset