Working with multiple Macros within another macro

Hi everybody,

I’ve read the Imagej Documentation and Programmer’s Reference Guide and have a couple of questions/doubts regarding the coding of macros. I’ll use the following macro as an example:

var x=1;
macro "Macro1..." {
	x = getNumber("x:", x);
macro "Macro2" {
  1. Running this macro will read the 1st macro and stop at line 5.
    Is this an inherent property of ImageJ’s macros?
    Will any macro read its first macro and stop?

(I know I can work around it with “if” statements, functions or just installing them)

  1. Running the same macro without line 1 will result in an error, which is what you would expect. Installing and running “Macro1” and “Macro2” will load the global variable last value.
    How can I check on global variables the same way you would debug a macro?
    How do clear theses variables?

Thank you in advance.

Good day,

I think what you should consider are User-defined macro-functions.
Section 8.5 in this doc:

In any case it is a good idea to avoid using global variables. I know that sometimes you can only avoid them by using complicated constructs but these cases are rare.



1 Like

Thank you for your prompt response.