Skip to content

Instantly share code, notes, and snippets.

@fofr
Created May 26, 2023 22:15
Show Gist options
  • Save fofr/6bed2359717b8b667f736f4ba508954c to your computer and use it in GitHub Desktop.
Save fofr/6bed2359717b8b667f736f4ba508954c to your computer and use it in GitHub Desktop.
Photoshop grid selection
// Get a reference to the active document.
var doc = app.activeDocument;
// Set the height of the selection to the height of the document.
var height = doc.height;
// Set the x and y offset in pixels.
var xOffset = 5;
var yOffset = 5;
// Remove any existing selections.
doc.selection.deselect();
// Set the size of the grid.
var gridSize = 100;
// Set the horizontal and vertical margins between the grids.
var horizontalMargin = 100;
var verticalMargin = 100;
// Loop through the document width or height with a step of gridSize + horizontalMargin.
for(var x = 0; x < doc.width; x += gridSize + horizontalMargin) {
for(var y = 0; y < doc.height; y += gridSize + verticalMargin) {
// Create a selection that is gridSize wide and gridSize high.
doc.selection.select([
[x + xOffset, y + yOffset], // Top left corner
[x + xOffset + gridSize, y + yOffset], // Top right corner
[x + xOffset + gridSize, y + gridSize + yOffset], // Bottom right corner
[x + xOffset, y + gridSize + yOffset] // Bottom left corner
], SelectionType.EXTEND);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment