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.
Thanks |
Hi Bob,
you can use the ImageJ Prefs to pass parameters between macros, but that's not a very nice way of programming. See this previous post for an expample: https://list.nih.gov/cgi-bin/wa.exe? A2=ind0909&L=IMAGEJ&P=R29962&1=IMAGEJ&9=A&J=on&d=No+Match%3BMatch% 3BMatches&z=4 Michael ________________________________________________________________ On 3 Dec 2010, at 13:38, Bob 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. > > Thanks |
In reply to this post by Bob Loushin
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 |
I see. And if there is more than one input, I can use split to break up the
string, and things like parseInt to convert it to whatever the parameters are supposed to be. Slightly awkward, but doable. Thank you, Gabriel! Bob -----Original Message----- From: Gabriel Landini Sent: Friday, December 03, 2010 11:14 AM To: [hidden email] Subject: Re: Making and using macros with arguments 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 |
Free forum by Nabble | Edit this page |