Skip to main content
Known Participant
June 23, 2021
Answered

Merge group by name

  • June 23, 2021
  • 3 replies
  • 2281 views

Hello.

 

I want to merge these groups that have similar names
And then do the naming correctly, like the sample image

 

For example: Merge group :

"1-Black copy" & "1-Black" and rename to "1-Black"
"2-Navy Blue copy" & "2-Navy Blue" and rename to "2-Navy Blue"
"3-Crimson copy" & "3-Crimson" and rename to "3-Crimson"
"4-Vidas Blue copy" & "4-Vidas" Blue" and rename to "4-Vidas"

 

Thank you.

 

 

 

This topic has been closed for replies.
Correct answer JJMack

You can select more than one Group in a action however you can not select groups with similar names the exact name must be recorded in the Action and The Action may not work correctly if there are more than one group with the Recorded Name in the Document the Action is played on only one of the groups  the  correct will be seleted.

3 replies

Kukurykus
Legend
June 23, 2021

 

sTT = stringIDToTypeID
dsc = new ActionDescriptor()
//	lSs = activeDocument.layerSets;
lSs = activeDocument.activeLayer.layerSets;
(setsToMerge = Array().slice.call(lSs)).sort()
while(lengthOfGroups = setsToMerge.length) {
	if (cndtn = !(lengthOfGroups % 2)) ref = new ActionReference()
	ref.putName(sTT('layer'), nme = setsToMerge.shift().name); if (!cndtn) {
		dsc.putReference(sTT('null'), ref); executeAction(sTT('select'), dsc)
		runMenuItem(sTT('ungroupLayersEvent')); (ref1 = new ActionReference()).putClass
		(lS = sTT('layerSection')); (dsc1 = new ActionDescriptor()).putReference(sTT('null'), ref1);
		(ref2 = new ActionReference()).putEnumerated(sTT('layer'), sTT('ordinal'), sTT('targetEnum'))
		dsc1.putReference(sTT('from'), ref2); (dsc2 = new ActionDescriptor()).putString(sTT('name'), nme)
		dsc1.putObject(sTT('using'), lS, dsc2), executeAction(sTT('make'), dsc1)
	}
}

 

JavadstAuthor
Known Participant
June 23, 2021

Thank you very much.

The script worked properly, there is only one problem.

I think if the layers are a subset of another group it will show the following error message:


Error 21: undefined is not an object.
Line: 7
-> ref.putName(sTT('layer'), nme = pair.shift().name);

Kukurykus
Legend
June 23, 2021

Before you replied I updated script to other version you may try. See if you have same error.

What do you mean layers are subset of another group - are you referring to original image?

I understand your screenshot does not show upper containers, then you have to change:

 

lSs = activeDocument.layerSets;

 

to:

 

lSs = activeDocument.activeLayer.layers;

 

Ps. I added it now to the script. Remember to select main group before running!

c.pfaffenbichler
Community Expert
Community Expert
June 23, 2021

Why did you add » copy« in the first place? 

JavadstAuthor
Known Participant
June 23, 2021

These layers are not the same, they were not actually copied.
It is copied from different layers with the same type of name and must be merged together.

c.pfaffenbichler
Community Expert
Community Expert
June 23, 2021

But why did you add » copy« to the names? 

One can turn that off … 

JJMack
Community Expert
Community Expert
June 23, 2021

You would need to script that processing.  That process requires the use of logic.  Actions are recorded steps all setting are recorded fixed setting.   You also have to be careful using names for names may not be unique

JJMack
JavadstAuthor
Known Participant
June 23, 2021

My problem is that I can not select 2 groups using action, only one layer is selected. If this problem is solved, I have no problem using action with fixed setting...

JJMack
Community Expert
JJMackCommunity ExpertCorrect answer
Community Expert
June 23, 2021

You can select more than one Group in a action however you can not select groups with similar names the exact name must be recorded in the Action and The Action may not work correctly if there are more than one group with the Recorded Name in the Document the Action is played on only one of the groups  the  correct will be seleted.

JJMack