Answered
This topic has been closed for replies.
I am not 100% happy with the following script, however, it has taken longer to get to this point than I expected. I believe that it works as required, let me know how you go.
/*
Distribute Grouped Layer Stack Horizontally From Left to Right.jsx
v1.0, 28th November 2022, Stephen Marsh
https://community.adobe.com/t5/photoshop-ecosystem-discussions/align-the-image-layers-laterally-through-the-group-layer/td-p/13375249
*/
#target photoshop
function main() {
if (activeDocument.activeLayer.typename === "LayerSet") {
var setName = activeDocument.activeLayer.name;
var count = activeDocument.activeLayer.layers.length;
activeDocument.activeLayer = activeDocument.layerSets[setName].layers[count - 1];
var lyrRight = activeDocument.activeLayer.bounds[2].value;
for (var i = count - 1; i >= 0; i--) {
selectForwardORBackwardLayer(false, "forwardEnum");
activeDocument.activeLayer.translate((lyrRight));
var lyrRight = activeDocument.activeLayer.bounds[2].value;
}
// It's a hack, however, it will have to do for now!
align2SelectAll('AdLf');
//activeDocument.revealAll();
} else {
alert("Please select a layer group containing the layers to distribute from left to right!");
}
}
activeDocument.suspendHistory("Undo script...", "main()");
// Functions
function selectForwardORBackwardLayer(makeVisible, forwardORbackward) {
var s2t = function (s) {
return app.stringIDToTypeID(s);
};
var descriptor = new ActionDescriptor();
var list = new ActionList();
var reference = new ActionReference();
// "forwardEnum" or "backwardEnum"
reference.putEnumerated(s2t("layer"), s2t("ordinal"), s2t(forwardORbackward));
descriptor.putReference(s2t("null"), reference);
// true or false
descriptor.putBoolean(s2t("makeVisible"), makeVisible);
list.putInteger(15);
descriptor.putList(s2t("layerID"), list);
executeAction(s2t("select"), descriptor, DialogModes.NO);
}
function align2SelectAll(method) {
/* https://gist.github.com/MarshySwamp/df372e342ac87854ffe08e79cbdbcbb5 */
/*
AdLf = Align Left
AdRg = Align Right
AdCH = Align Centre Horizontal
AdTp = Align Top
AdBt = Align Bottom
AdCV = Align Centre Vertical
*/
app.activeDocument.selection.selectAll();
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
desc.putReference(charIDToTypeID("null"), ref);
desc.putEnumerated(charIDToTypeID("Usng"), charIDToTypeID("ADSt"), charIDToTypeID(method));
try {
executeAction(charIDToTypeID("Algn"), desc, DialogModes.NO);
} catch (e) {}
app.activeDocument.selection.deselect();
}
Sign up
Already have an account? Login
To post, reply, or follow discussions, please sign in with your Adobe ID.
Sign inSign in to Adobe Community
To post, reply, or follow discussions, please sign in with your Adobe ID.
Sign inEnter your E-mail address. We'll send you an e-mail with instructions to reset your password.


