I have a simple PSD with a layer group called "faces", and there are 24 layers in it, each 175x175 pixels.
I want to automatically arrange those into a 6x4 grid.
When I run this script (with help from https://stackoverflow.com/a/12064474/470749), my layers each seem to get erased, sort of. They still exist, but the contents now appear empty.
How can I fix this?
// Check if we are running inside Adobe Photoshop
if (app.name !== "Adobe Photoshop") {
alert("This script works only with Adobe Photoshop.");
} else {
main();
}
function main() {
var groupName = "faces";
var itemWidth = 175;
var itemHeight = 175;
// Define the grid dimensions
var columns = 6;
var rows = 4;
// Get the active document
var doc = app.activeDocument;
var layerSets = doc.layerSets;
var facesGroup = layerSets.getByName(groupName);
// Check if the group exists
if (facesGroup) {
// Iterate over layers in the "faces" group
for (var i = 0; i < facesGroup.artLayers.length; i++) {
var currentLayer = facesGroup.artLayers[i];
// Set the active layer
doc.activeLayer = currentLayer;
// Get a reference to the active layer
var layer = doc.activeLayer;
// Calculate column and row
var column = i % columns;
var row = Math.floor(i / columns);
// Calculate x, y position
var x = column * itemWidth;
var y = row * itemHeight;
// FIXNOW: Why does this not work?!
MoveLayerTo(layer, x, y);
}
alert("Completed.");
} else {
alert("Group named 'faces' not found.");
}
}
function MoveLayerTo(fLayer,fX,fY) {
// https://stackoverflow.com/a/12064474/470749
var Position = fLayer.bounds;
Position[0] = fX - Position[0];
Position[1] = fY - Position[1];
fLayer.translate(-Position[0],-Position[1]);
}
Image > Reveal All
seems to have no effect, so I guess nothing was out of frame. Double-clicking each layer (smart object) takes me into the layer where the images look normal and untouched. It's only when I'm not "inside" that smart layer that they look empty. @Scott