Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Javascript to flatten/merge/rasterize specifically named subgroups

New Here ,
Aug 18, 2021 Aug 18, 2021

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();

}

}

}

 

TOPICS
Actions and scripting
607
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Community Expert ,
Aug 18, 2021 Aug 18, 2021

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,

JJMack
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 18, 2021 Aug 18, 2021

Is there another community forum that I could talk to that could help with coding a new script?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 18, 2021 Aug 18, 2021

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.

JJMack
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 20, 2021 Aug 20, 2021

Post screenshot of your layer(Set)s tree.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 21, 2021 Aug 21, 2021

Screen Shot 2021-08-21 at 2.16.41 PM.png

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.

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 21, 2021 Aug 21, 2021
LATEST
(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)
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines