Copy link to clipboard
Copied
Hi, I currently have a "flatten.js" javascript that will merge any visible layers in top level groups to a be 1 layer flattened. However, I need it to go through the photoshop file and only flatten nested subgroups with specific prefix's. So for example of the folder structure I have P: Main > BOG: Play > B: Play > then multiple folders= A1: Play, S1: Play, N1: Play. I need those last 3 folders to be flat but stay seperate layers. This is the current script I have, but it is buggy with Photoshop 2021. A new script that works would be very helpful. Thank you
Flatten.js:
var doc;
if(documents.length > 0) {
doc = activeDocument;
recurse(doc);
alert("Flattening complete!");
}
function recurse(psdoc) {
for(var i = 0; i < psdoc.layers.length; i++) {
if(psdoc.layers[i].name == "guides" || psdoc.layers[i].name == "background") {
continue;
} else if(psdoc.layers[i].name.match(/^div:/)) {
if(psdoc.layers[i].layers) {
alert("recurse");
recurse(psdoc.layers[i]);
}
} else {
// flatten
psdoc.layers[i].mergeDown();
}
}
}
Copy link to clipboard
Copied
You would need to code the script to process your layered file the he way you want them to be processed. All you file shoulds have a common layer structure that the script is coded to processs,
Copy link to clipboard
Copied
Is there another community forum that I could talk to that could help with coding a new script?
Copy link to clipboard
Copied
This forum is one of the best on the web for that. However, to receive good help you will need to post your process design and the code your working on. The script you have does not do what you want to do and what you posted you want to do is less then vague. There is no actual details about what you want to do or any details about the document you want to process with your automated script procedures.
Copy link to clipboard
Copied
Post screenshot of your layer(Set)s tree.
Copy link to clipboard
Copied
So this is a screen shot of the group folders structure I have, the script doesnt necessarily have to go into 5 levels of folders (I can remove the top Folder, but it would need to go into 3 or 4 levels into a group folder. In the screenshot I've manually flattened groups I need the script to flatten.
Copy link to clipboard
Copied
(function(v){
var lrs = [].slice.call(v); while(lrs.length) {
/^[ASN]1/.test((lS = lrs.shift()).name)
&& lS.layers.length ? lS.merge()
: callee(lS.layerSets)
}
})(activeDocument.layerSets)
Find more inspiration, events, and resources on the new Adobe Community
Explore Now