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

How to merge multiple groups and keep them on their separate layers?

Community Beginner ,
Mar 07, 2018 Mar 07, 2018

Copy link to clipboard

Copied

Hi Guys

 

I'm sure there is a really simple way to do this but I can't find the answer anywhere!

 

When I create multiple groups on separate layers, there must be a quicker way then right clicking and individually merging each layer so they stay on their respective layers?

 

A shortcut would save so much time!!

 

Thanks

 

Screen Shot 2018-03-07 at 12.25.06.png

TOPICS
Actions and scripting

Views

13.5K

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
community guidelines

correct answers 1 Correct answer

LEGEND , Mar 07, 2018 Mar 07, 2018

I can't help right now but move your topic to Photoshop Scripting  and ask of help r-bin​ that should be easy for him

 

function sTT(v) {return stringIDToTypeID(v)} $.level = 0

function R() {return ref = new ActionReference()} arr = []

 

function DoL(v) {R().putEnumerated(sTT(v), sTT('ordinal'), sTT('targetEnum'))}

 

function bGrnd(v) {R().putIndex(sTT('layer'), v)}

 

function SC(v) {

     return typeIDToStringID((dsc = executeActionGet(ref))

     .getEnumerationValue(sTT(lS = 'layerSection')))

...

Votes

Translate

Translate
Adobe
Advocate ,
Mar 07, 2018 Mar 07, 2018

Copy link to clipboard

Copied

First select all groups and

Just use CTRL+E or Cmd+E on mac shortcut - and thats all

pawel

Votes

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
community guidelines
Community Beginner ,
Mar 07, 2018 Mar 07, 2018

Copy link to clipboard

Copied

Almost there, but these commands only do one layer at a time, or if select all and then Cmd+E it merges all layers into one layer.

Doesn't take long to Cmd+E individual layers, but would be quicker if I could do all layers at the same - prob not!

Thanks anyway

Votes

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
community guidelines
LEGEND ,
Mar 07, 2018 Mar 07, 2018

Copy link to clipboard

Copied

I can't help right now but move your topic to Photoshop Scripting  and ask of help r-bin​ that should be easy for him

 

function sTT(v) {return stringIDToTypeID(v)} $.level = 0

function R() {return ref = new ActionReference()} arr = []

 

function DoL(v) {R().putEnumerated(sTT(v), sTT('ordinal'), sTT('targetEnum'))}

 

function bGrnd(v) {R().putIndex(sTT('layer'), v)}

 

function SC(v) {

     return typeIDToStringID((dsc = executeActionGet(ref))

     .getEnumerationValue(sTT(lS = 'layerSection'))) == lS + v

}

 

function sNL() {

     DoL('layer'); (dsc = new ActionDescriptor()).putReference(sTT('null'), ref)

     executeAction(sTT('selectNoLayers'), dsc, DialogModes.NO)

}

 

function mLN(v) {

     R().putIdentifier(sTT('layer'), v);

     (dsc = new ActionDescriptor()).putReference(sTT('null'), ref)

     dsc.putBoolean(sTT('makeVisible'), true)

     executeAction(sTT('select'), dsc, DialogModes.NO)

     executeAction(sTT('mergeLayersNew'), undefined, DialogModes.NO)

}

 

function prcs(v1, v2) {

     bGrnd(idx = v1), lID = executeActionGet(ref).getInteger(sTT('layerID'))

     if (SC('Start')) {

          bGrnd(idx - 1); if (SC('Content')) v2 ? arr.push(lID) : (sNL(), mLN(lID))

     }

}

 

try{

     R().putIdentifier(sTT('layer'), 1)

     bG = !(executeActionGet(ref))

     .getBoolean(sTT('background'))

}

catch (err) {bG = 1}

 

DoL('document'), tL = sTT('targetLayers')

if ((dsc = executeActionGet(ref)).hasKey(tL)) {

     for(lst = dsc.getList(tL), i = 0; i < lst.count;) {

          prcs(lst.getReference(i++).getIndex() + bG, true)

     }

     sNL(); for(i = 0; i < arr.length; i++) mLN(arr[i])

}

else {

     DoL('layer'), prcs(executeActionGet(ref)

     .getInteger(sTT('itemIndex')) - !bG, false)

}

Votes

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
community guidelines
Community Beginner ,
Nov 14, 2018 Nov 14, 2018

Copy link to clipboard

Copied

Kukurykus your script is very helpful I managed to solve my problem with your script. Thanks a lot

Votes

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
community guidelines
LEGEND ,
Nov 14, 2018 Nov 14, 2018

Copy link to clipboard

Copied

What was your problem?

Votes

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
community guidelines
Explorer ,
Feb 07, 2020 Feb 07, 2020

Copy link to clipboard

Copied

Hi - Thanks for this, I tried this code, but when I select more than one layer, I get the following error message:

 

Error 1243: Illegal argument - argument 2

- Numeric value expected

Line: 14

->       R().putIdentifier(sTT('layer'), v);

 

Any ideas? The code would be REALLY useful for me as I often need to flatten multiple layers into individual groups.

Votes

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
community guidelines
LEGEND ,
May 29, 2020 May 29, 2020

Copy link to clipboard

Copied

Leave a link to uploaded .psd so I try script on and see what is wrong.

 

btw moderator, other user confimred script works for him so I marked my solution as correct. Please add 'Actions and scripting' label to post of original poster, thx!

Votes

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
community guidelines
Explorer ,
Mar 03, 2021 Mar 03, 2021

Copy link to clipboard

Copied

Hi Kukurykus
Sorry for my bad english
For simple groups, your script is working fantastic,
but when i try to merge some complex nested groups, it cant merge all of them
i have attached a video which can explain the issue more clearly
i need groups to be merged completely into a single layer.
can you please help me?
agian sorry for my bad english.
Thanks a lot

Votes

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
community guidelines
LEGEND ,
Mar 03, 2021 Mar 03, 2021

Copy link to clipboard

Copied

Can you check in those groups by removing single layers which one causes they can't be merged?

Votes

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
community guidelines
Explorer ,
Mar 03, 2021 Mar 03, 2021

Copy link to clipboard

Copied

I removed the layers one by one and checked whether is working... But layers were not the issue.

and I also tried removing the layer mask, and the mask was also not the issue.

but when I ungrouped the inner group, it was working

I think its the issue.

I have attached the video and PSD.

Thanks a lot for helping.

Agian sorry for my bad english.

Votes

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
community guidelines
LEGEND ,
Mar 04, 2021 Mar 04, 2021

Copy link to clipboard

Copied

Change:

SC('Content')

to:

executeActionGet(ref).getInteger(sTT('parentLayerID'))

Votes

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
community guidelines
Explorer ,
Mar 04, 2021 Mar 04, 2021

Copy link to clipboard

Copied

Hi Kukurykus,

I have changed the code as you said

Screenshot_3.png

 

and I am getting this error

Screenshot_1.png

I am using Photoshop CC 2019

Screenshot_2.png

please help me with this issue or let me know if I did anything wrong...

and Thanks for helping me, I really appreciate it.

Votes

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
community guidelines
LEGEND ,
Mar 04, 2021 Mar 04, 2021

Copy link to clipboard

Copied

Update to release 22.

Votes

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
community guidelines
Explorer ,
Mar 05, 2021 Mar 05, 2021

Copy link to clipboard

Copied

Hi Kukurykus,

I have updated to 22, and your script works very well

but it still has a small error.

it reveals and merges the inner groups, it's not merging the group as it is.

can you please help me with this?

I have attached the error video and error PSD

sorry to asking again and again,

but I really need this, it can save my time a lot

 

Thanks a lot...

Votes

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
community guidelines
LEGEND ,
Mar 06, 2021 Mar 06, 2021

Copy link to clipboard

Copied

Change:

bGrnd(idx - 1); if (executeActionGet(ref).getInteger(sTT('parentLayerID')))

to:

if (!(executeActionGet(ref).getInteger(sTT('parentLayerID')) + 1))

Votes

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
community guidelines
Explorer ,
Mar 09, 2021 Mar 09, 2021

Copy link to clipboard

Copied

Hi Kukurykus,

Thanks a lot for helping me,

I got one more error.

the script is working good when the groups are simple

if I try to merge the groups that are inside another group, the script is not working

can you please help me with this?

I have attached the error video and error PSD

Votes

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
community guidelines
Community Expert ,
Mar 09, 2021 Mar 09, 2021

Copy link to clipboard

Copied

I'm just curious, what if you select the layer group and convert to smart object, then select the smart object and select rasterize smart object?

Votes

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
community guidelines
Explorer ,
Mar 10, 2021 Mar 10, 2021

Copy link to clipboard

Copied

Hi, 

Thanks for the reply

I have a large number of groups,
if I select the layer group and convert it to a smart object, then select the smart object and select rasterize smart object, it would be a big process and it would take too much time than usual

Votes

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
community guidelines
LEGEND ,
Mar 10, 2021 Mar 10, 2021

Copy link to clipboard

Copied

Change:

 

SC('Content')

 

in known line of original code to:

 

executeActionGet(ref).getInteger(sTT('parentLayerID')) == lID

 

To avoid merging inner groups, select layerSets without holding Shift, but only using Ctrl.

Votes

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
community guidelines
Explorer ,
Mar 10, 2021 Mar 10, 2021

Copy link to clipboard

Copied

Thank You So Much...

Votes

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
community guidelines
People's Champ ,
Mar 04, 2021 Mar 04, 2021

Copy link to clipboard

Copied

Will this decision suit you?

Script to Merge each main group (not subgroup) in to a layer

 

The script merges all zero-level groups, even empty ones.

You do not need to preselect them.

Votes

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
community guidelines
Explorer ,
Mar 05, 2021 Mar 05, 2021

Copy link to clipboard

Copied

Hi r-bin

Thanks for the reply

your script works great when its come to merging all group in the entire document

but I need to select and merge the groups.

Thanks for the help, really

Votes

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
community guidelines
Explorer ,
Mar 01, 2021 Mar 01, 2021

Copy link to clipboard

Copied

This is HUGE help, it worked flawlessly

Votes

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
community guidelines
New Here ,
Aug 18, 2021 Aug 18, 2021

Copy link to clipboard

Copied

This works perfectly, thank you so much!

Votes

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
community guidelines