Skip to content, Skip to search


Introduction into Macro Programming

10 bytes added, Yesterday at 10:54
Use HTTPS links where feasible
= Functions =
Most of the time, you will call ''functions'' which implement the actions you want to execute. Functions have names, like variables, but they also have ''parameters'' that you can pass to the functions. ImageJ comes with many [http predefined functions] that you can call to perform specific calculations or other operations.
This example writes ''Hello, World!'' to the ''Log'' window:
= Installing macros =
To install keyboard shortcuts or tool icons, you need to [http wrap macro code in ''macro'' blocks]:
<source lang="java">
The icon is defined by a funny-looking string (in this case, ''C000R11ee''). To learn how to define your own icon, please have a look [http here].
Many tools open an option dialog upon double-click on the icon. You can do that, too, by choosing a name that ends in ''Action Tool Options'':
== More example macros ==
There are quite a lot of macros on the [http ImageJ website], and specifically [http example macros] including a few from the Macro workshop at the [ ImageJ conference 2010]. Since there is no categorized index, you might want to use the search facility on [http this page].
= Overcoming limitations =
== Macro extensions ==
It is possible to implement code in [[Java]] which extends the macro language via the [http <code>Ext</code> prefix]. However, this cannot be done within the macro itself.
== The call function ==
The [http <code>call</code> function] can invoke Java methods directly. However, this function only supports calling <code>public static</code> Java methods which accept <code>String</code> only, and return <code>String</code> only. Most times, though, the needed function does not conform to these requirements; this approach is suitable mostly for routines designed to be called from the macro language in this way.
== The eval function ==
The [http <code>eval</code> function] can execute [[JavaScript]] (or [[BeanShell]] or [[Python]]) code directly. This is a powerful and flexible approach which can invoke nearly any Java API without needing to write external Java code.
Here is an example which sets the position of a [[3D Viewer]] window:
= Further documentation =
A complete description of the macro language, a reference of the built-in functions, and examples can be found [http here].
Bureaucrat, emailconfirmed, incoming, administrator, uploaders