Hi @sjohnson,

Welcome to the forums!

Yes! I have made a script that I think works well. To run the script, copy and paste it in to the script editor (use the `[`

key to open the script editor) and select the language as “IJ1 Macro”. It is commented, but feel free to ask any questions.

```
roiManager("reset");
mainWindow = getTitle();
close("\\Others"); // close all but selected window
h = getHeight;
w = getWidth;
area = w*h;
gridNum = getNumber("How many grid boxes in total?",100);
boxArea = area/gridNum; // area of each grid box
boxSide = sqrt(boxArea); // side length of each grid box
numBoxY = floor(h/boxSide); // number of boxes that will fit along the width
numBoxX = floor(w/boxSide); // "" height
remainX = (w - (numBoxX*boxSide))/2; // remainder distance left when all boxes fit
remainY = (h - (numBoxY*boxSide))/2;
for (i=0; i<numBoxY; i++) { // draws rectangles in a grid, centred on the X and Y axes and adds to ROI manager
for (j=0; j<numBoxX; j++) {
makeRectangle((remainX + (j*boxSide)), (remainY+(i*boxSide)), boxSide, boxSide);
roiManager("add");
}
}
grids = getNumber("How many grid boxes to select?", 10);
boxID = newArray(grids);
gridTotal = roiManager("count"); // not neccessarily as many boxes in the grid as specified due to the constraint of # squares not fitting the width/height
for (i=0; i<grids; i++) { // generate random number to select a square in the grid, makes sure the square has not already been chosen
randNum = round(random*gridTotal);
for (j=0; j<boxID.length; j++) {
if (randNum == boxID[j]) {
randNum = round(random*gridTotal);
j=0;
}
}
boxID[i] = randNum;
selectWindow(mainWindow);
roiManager("select", boxID[i]);
run("Duplicate...", "duplicate"); // duplicates the random square in the grid box
rename("Grid " + i);
}
for (i=0; i<grids; i++) {
selectWindow("Grid " + i);
pointX = round(random*boxSide); // random X coord
pointY = round(random*boxSide); // random Y coord
makePoint(pointX, pointY);
}
```

I don’t know if there is already a function to make a grid, or code online (I assume you searched), but this is the best I could come up with.

EDIT: turns out there is a grid plugin - https://imagej.nih.gov/ij/plugins/grid.html (other examples of grid plugins/macros are available from this page also).