Highlighted

Script “Merge by layerset name”

Community Beginner ,
Feb 28, 2020

Copy link to clipboard

Copied

Script “Merge by layerset name”

 

Hi,

in advance ,sorry for my poor English.

I’ll do my best to convey the meaning of the sentence.

 

I’m Japanese photoshop user,and also very big inner to programming.

I need some advice to scripting.

 

I made some very simple script to photoshop .

.JSX contents is like this:

------------------------------------------------

try{

    while(

    lsObj = activeDocument.layerSets["item"] ) {

lsObj.merge();

}}

catch(e){

; // do nothing

}

------------------------------------------------

I wanted to merge each layer sets named by each specific keywords before sending to coworker.

The order is like this .[Merge every layer sets only named “item”]

Usually on the graphic design job,I use ton of PSD file and also after working in photoshop ,each PSD file will be so heavy.

that why I made this scrip to lighten file and put into droplet to automate the process.

Fortunately It works.

 

Take up to the main question.Now I’m thinking remodeling little bit this script.

I feel unuseful ,because of the Keyword is to much specific .

Some times on the job,I need to put ohther name like “main item”or”item A,B,C.....etc”.

Every moment in this case,I have to rename keyword before running the script.

So now I’m thinking,trying to find the way to place an order like [Merge every layer sets only  include string“item”]

Ideally,it will merge every layer sets only what I want to merge.

I tryed to use “indexOf()” or maybe other code but it couldn’t work.

I don’t have the basic programming knowledge.

Please give me some advice If someone know how to do this or have an idea about this.

Hope the sentence convey meaning.

thank you for reading to the end.

Adobe Community Professional
Correct answer by r-bin | Adobe Community Professional
var sets = new Array();

var match = "item";

// collect LayerSets of zero level of nesting

for (var i = 0; i < activeDocument.layerSets.length; i++) sets.push(activeDocument.layerSets[i]);

// loop through sets and merge needed (with word "item")

for (var i = 0; i < sets.length; i++) 
    {
    if (sets[i].name.search(new RegExp(match, "i")) >= 0) sets[i].merge();
    }
TOPICS
How to

Views

297

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Script “Merge by layerset name”

Community Beginner ,
Feb 28, 2020

Copy link to clipboard

Copied

Script “Merge by layerset name”

 

Hi,

in advance ,sorry for my poor English.

I’ll do my best to convey the meaning of the sentence.

 

I’m Japanese photoshop user,and also very big inner to programming.

I need some advice to scripting.

 

I made some very simple script to photoshop .

.JSX contents is like this:

------------------------------------------------

try{

    while(

    lsObj = activeDocument.layerSets["item"] ) {

lsObj.merge();

}}

catch(e){

; // do nothing

}

------------------------------------------------

I wanted to merge each layer sets named by each specific keywords before sending to coworker.

The order is like this .[Merge every layer sets only named “item”]

Usually on the graphic design job,I use ton of PSD file and also after working in photoshop ,each PSD file will be so heavy.

that why I made this scrip to lighten file and put into droplet to automate the process.

Fortunately It works.

 

Take up to the main question.Now I’m thinking remodeling little bit this script.

I feel unuseful ,because of the Keyword is to much specific .

Some times on the job,I need to put ohther name like “main item”or”item A,B,C.....etc”.

Every moment in this case,I have to rename keyword before running the script.

So now I’m thinking,trying to find the way to place an order like [Merge every layer sets only  include string“item”]

Ideally,it will merge every layer sets only what I want to merge.

I tryed to use “indexOf()” or maybe other code but it couldn’t work.

I don’t have the basic programming knowledge.

Please give me some advice If someone know how to do this or have an idea about this.

Hope the sentence convey meaning.

thank you for reading to the end.

Adobe Community Professional
Correct answer by r-bin | Adobe Community Professional
var sets = new Array();

var match = "item";

// collect LayerSets of zero level of nesting

for (var i = 0; i < activeDocument.layerSets.length; i++) sets.push(activeDocument.layerSets[i]);

// loop through sets and merge needed (with word "item")

for (var i = 0; i < sets.length; i++) 
    {
    if (sets[i].name.search(new RegExp(match, "i")) >= 0) sets[i].merge();
    }
TOPICS
How to

Views

298

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Feb 28, 2020 0
Adobe Community Professional ,
Feb 28, 2020

Copy link to clipboard

Copied

Hi kiiso does this help?

 

The script is now interactive, asking for a case sensitive layer set name, so perhaps no longer good for a droplet...

 

 

if (app.documents.length != 0) {
	var setName = prompt("Enter the case sensitive layer set name to merge:", "item");
	function main() {
		try {
			while (
				lsObj = app.activeDocument.layerSets[setName]) {
				lsObj.merge();
			}
		} catch (e) {
			// do nothing
		}
	}
	app.activeDocument.suspendHistory("Named layer set merge", "main()");
} else {
	alert('You must have a document open to use this script!');
}

 

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 28, 2020 1
Community Beginner ,
Feb 29, 2020

Copy link to clipboard

Copied

Hi Stephen .

Thank you very much to your help. Yes you're right ,but it is also interesting ,It comes to mind another ideas to make job easier.

that's very helpful to me.

thank you again and have a nice day!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 29, 2020 0
Adobe Community Professional ,
Feb 28, 2020

Copy link to clipboard

Copied

var sets = new Array();

var match = "item";

// collect LayerSets of zero level of nesting

for (var i = 0; i < activeDocument.layerSets.length; i++) sets.push(activeDocument.layerSets[i]);

// loop through sets and merge needed (with word "item")

for (var i = 0; i < sets.length; i++) 
    {
    if (sets[i].name.search(new RegExp(match, "i")) >= 0) sets[i].merge();
    }

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 28, 2020 2
Community Beginner ,
Feb 29, 2020

Copy link to clipboard

Copied

Hi r-bin .

Thank you very much to your help.

I’ve tried and it works. Genius,this is what I want .

It is difficult to understand whole code yet,but I will try to understand the logic.

I appreciate it very much and have a nice day!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 29, 2020 0
Community Beginner ,
Oct 20, 2020

Copy link to clipboard

Copied

Is it possible to tweak the script above so that it will still merge all layer sets with a specific name (ie Product or Shadow), withtout having a nesting level of zero?

 

When I make simplified psds with merged sets to give clients, I often put sets called Shadow and Product inside folders that describe what they are. For example, I would have a layer set called Phone, and nested inside there are two more sets called Product and Shadow. Many times there is more than one product in an image, so having Product and Shadow nested inside sets like Phone, Computer, Tablet etc is neccesary.

 

Any help will be greatly appriciated! You guys rock!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 20, 2020 0