break
Exit a while() or for() loop. continue
Jump back to the beginning of a while() or for() loop. else {
All commands inside an else block are executed if the expression in the earlier if block is false. filelist = getFileList(directory)
for (i = 0; i < lengthOf(filelist); i++) {
if (endsWith(filelist[i], ".tif")) {
open(directory + File.separator + filelist[i]);
}
}
A for loop which opens all files ending with ".tif" in a folder. for (i = 1; i <= nSlices; i++) {
setSlice(i);
// do something here;
}
A for loop which loops over slices in a stack. n = roiManager('count');
for (i = 0; i < n; i++) {
roiManager('select', i);
// process roi here
}
A for loop which loops over ROIs in the ROI Manager. for (i = 0; i < nResults(); i++) {
v = getResult('Area', i);
setResult('myColumn', i, v);
}
updateResults();
A for loop which loops over results in the Results Table. for (i = 0; i < 10; i++) {
All commands inside a for loop block are repeatedly executed. function doSomething() {
// function description

Defines a list of commands as function which can be called. if (expression) {
All commands inside an if block are only executed if expression is true. macro "title" {
Macro sets can be defined to make reusable macro available via ImageJs menu, the toolbar or via shortcuts. See documentation for more details. print("\\Clear") Empty the log window. print("\\Update:[text]") Update the recent line of the log window by replace its content by [text]. print("\\Update[n]:[text]") Update the [n+1]th line of the log window by replace its content by [text]. var
The
var
statement allows defining global variables which are available from different macros. See documentation for more details. while (expression) {
All commands inside a while loop block are repeatedly executed until expression becomes false. #@ String text Ask the user to enter a string when starting macro execution. #@ String(value="Useful hints", visibility="MESSAGE") hint Show a message to the user when starting macro execution. #@ String(label="Analyst name", description="Your name") name Ask the user to enter a string explained in a label when starting macro execution. #@ String(choices={"A","B"}, style="radioButtonHorizontal") location Ask the user to make a choice with radio buttons when starting macro execution. #@ String(choices={"Mutant", "Control"}, style="list") experimGroup Ask the user to make a choice in a pulldown when starting macro execution. #@ int number Ask the user to enter a number when starting macro execution. #@ int(value=25, min=0, max=100, style="slider") ratio2 Ask the user to enter a number within a given range using a slider when starting macro execution. #@ double(value=25, min=0, max=1, style="spinner") realNumber Ask the user to enter a number within a given range using a spinner when starting macro execution. #@ File (style="open") inputFile Ask the user to select a file to open when starting macro execution. #@ File (style="save") outputFile Ask the user to select a file to save when starting macro execution. #@ File (style="directory") imageFolder Ask the user to select a folder when starting macro execution. #@ ColorRGB(value="red") color Ask the user to select a colour when starting macro execution. #@ boolean checkbox Offer the user to activate a checkbox when starting macro execution.