Login  Register

Re: Making and using macros with arguments

Posted by Gabriel Landini on Dec 03, 2010; 5:14pm
URL: http://imagej.273.s1.nabble.com/Making-and-using-macros-with-arguments-tp3686300p3686301.html

On Friday 03 Dec 2010 06:38:54 Bob <[hidden email]> wrote:
> According to the manual for writing macros for ImageJ, I can define a
> function in the same macro file, and the macro can call it.  The function
> can take arguments, which the macro can pass to it.  But what if the
> function itself is general/useful/reusable enough to be a macro in its own
> right?  In other words, can one write a macro that takes in arguments?  If
> so, what is the syntax for writing the macro, and what is the syntax for
> calling it?  I didn’t find anything in the manual about this possibility,
> but I may have missed it.

This is modified from a set of macros that I have not used in some time, so
not sure if this still works.

Example:
In macro 1, you call the (let's say) "macro2" with a parameter and get the
result:

    x=runMacro("macro2", parameter_1);

Macro2 gets the parameters as a string

    the_called_parameter = getArgument();

and returns a result also as a string (in this case "1"):

    return toString(1);

so x in macro1 gets the result of "1".

Cheers

Gabriel