//@AutoInstall // This tool creates 200x200 square selections and // adds then to an overlay. Click on a square and drag // to move it. Alt click to remove it. Double click on // the tool icon to save the contents of the selections. // Based on the Help>Examples>Tools>Circle Tool // example. Requires ImageJ 1.53c14 or later. var size = 200; var leftButton = 16; var alt = 8; macro "Square Tool - C037R0055Rd355R7d55" { moving = false; getCursorLoc(x, y, z, flags); index = Overlay.indexAt(x,y); if (index>=0 && flags&alt!=0) { // delete? Overlay.removeSelection(index); exit; } if (index>=0) { // move Overlay.activateSelection(index); moving = true; } while (flags&leftButton!=0) { if (moving) Overlay.moveSelection(index, x-size/2, y-size/2); else makeRectangle(x-size/2, y-size/2, size, size); wait(10); getCursorLoc(x, y, z, flags); } if (!moving) Overlay.addSelection; Roi.remove; } macro "Square Tool Options" { msg = "Click \"OK\" to save contents of "+Overlay.size +" selections in \"Dir:\"; Dialog.create("Square Tool Options"); Dialog.addDirectory("Dir:", getDir("downloads")+"images/"); Dialog.addMessage(msg); Dialog.show(); dir = Dialog.getString(); Overlay.cropAndSave(dir, "png"); }