I am new to ImageJ macros and I want to use a macro in Fiji. The code for the macro is from this source.
macro "MultiRoiMove Tool - C00cT0f16M" {
if (RoiManager.selected<2) exit();
indexes=split(call("ij.plugin.frame.RoiManager.getIndexesAsString"));
roiManager("Combine");
getCursorLoc(x, y, z, modifiers);
Roi.getBounds(x0, y0, width, height);
while(modifiers&16>0) {
getCursorLoc(x1, y1, z, modifiers);
Roi.move(x0+x1-x, y0+y1-y);
}
roiManager("select", indexes);
roiManager("translate", x1-x, y1-y);
}
I have downloaded the code and saved it as a text file. I have then run the macro through going to Plugins > Macros > Run. The version of ImageJ I am using is 1.53j.
However, when I run the macro, I am getting the following error:
I have seen online on the ImageJ forum that this macro works for other people. I have done some debugging and know that I am getting the error because the code does not go into the while loop when I run the macro, so there isn't a value for x1
returned by the getCursorLoc
function.
But I am not how to get the code to go into the while loop. Does anyone know if I have to click something specific before running the macro? It seems to me that the code will go into the while loop when a mouse modifier event occurs (as the modifiers parameter returned by the getCursorLoc function are the mouse event modifier flags). Any help is appreciated.
You need to select the ROIs in the ROI Manager that you'd like to move. You can click the first one and then cmd + click (on Mac) to add additional ROIs. The macro will then move those ROIs but not any that are unselected.
The modifiers
part of the code receives which mouse buttons are being pressed and if the use left-clicks (16) and drags this defines a rectangle which is then used to move the ROIs.
You should choose Plugins > Macros > Install to get the tool added to the toolbar.