Working with multiple Macros within another macro

imagej

#1

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;
print("1");
macro "Macro1..." {
	x = getNumber("x:", x);
}
print("2");    
macro "Macro2" {
	print("x="+x);
}
print("3");    
  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.


#2

Good day,

I think what you should consider are User-defined macro-functions.
Section 8.5 in this doc:
https://imagej.nih.gov/ij/developer/macro/macros.html

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.

Regards

Herbie


#3

Thank you for your prompt response.