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

Group Selected Layers

Contributor ,
Aug 11, 2018 Aug 11, 2018

Copy link to clipboard

Copied

Is it possible to group all selected layers individually? Each layer would remain within the respective group. All help will be treasured.

TOPICS
Actions and scripting

Views

3.0K

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 2 Correct answers

LEGEND , Aug 11, 2018 Aug 11, 2018

CC 2018:

function sTT(v) {return stringIDToTypeID(v)}

(ref = new ActionReference()).putEnumerated

(sTT('document'), sTT('ordinal'), sTT('targetEnum'));

cnt = (lst = executeActionGet(ref).getList(sTT('targetLayersIDs'))).count

for(i = 0; i < cnt;) {

     id = lst.getReference(i++).getIdentifier();

     (ref1 = new ActionReference()).putClass(sTT('layerSection'));

     (dsc1 = new ActionDescriptor()).putReference(sTT('null'), ref1);

     (ref2 = new ActionReference()).putIdentifier(sTT('layer'), id)

     ds

...

Votes

Translate

Translate
Community Expert , Nov 03, 2022 Nov 03, 2022

Try this:

 

#target photoshop

function main() {

    ///// Process selected layers - from jazz-y /////
    var s2t = stringIDToTypeID;
    (r = new ActionReference()).putProperty(s2t('property'), p = s2t('targetLayersIDs'));
    r.putEnumerated(s2t('document'), s2t('ordinal'), s2t('targetEnum'));
    var lrs = executeActionGet(r).getList(p),
        sel = new ActionReference();
    for (var i = 0; i < lrs.count; i++) {
        sel.putIdentifier(s2t('layer'), p = lrs.getReference(i).getIdentifie
...

Votes

Translate

Translate
Adobe
LEGEND ,
Aug 11, 2018 Aug 11, 2018

Copy link to clipboard

Copied

CC 2018:

function sTT(v) {return stringIDToTypeID(v)}

(ref = new ActionReference()).putEnumerated

(sTT('document'), sTT('ordinal'), sTT('targetEnum'));

cnt = (lst = executeActionGet(ref).getList(sTT('targetLayersIDs'))).count

for(i = 0; i < cnt;) {

     id = lst.getReference(i++).getIdentifier();

     (ref1 = new ActionReference()).putClass(sTT('layerSection'));

     (dsc1 = new ActionDescriptor()).putReference(sTT('null'), ref1);

     (ref2 = new ActionReference()).putIdentifier(sTT('layer'), id)

     dsc1.putReference(sTT('from'), ref2);

     nme = executeActionGet(ref2).getString(sTT('name'));

     (dsc2 = new ActionDescriptor()).putString(sTT('name'), nme)

     dsc1.putObject(sTT('using'), sTT('layerSection'), dsc2)

     executeAction(sTT('make'), dsc1)

}

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
Contributor ,
Aug 12, 2018 Aug 12, 2018

Copy link to clipboard

Copied

Phenomenal your script Kukurykus

You are a genius. Thank you.

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 ,
Jun 19, 2020 Jun 19, 2020

Copy link to clipboard

Copied

Great, thanks !

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 29, 2020 Mar 29, 2020

Copy link to clipboard

Copied

How do I add the script into Photoshop 2019? I tried copying and pasting it into a text editor, saving as .jsx and loading it from the script menu but it just gives me a syntax error. Hoping to get this working because it's the only solution I've found on the web for making groups for each layer, and it would greatly speed up my process. Thanks in advance!

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 29, 2020 Mar 29, 2020

Copy link to clipboard

Copied

I don't use Mac, but there you have to change format when saving .jsx script in text editor. Make research.

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 30, 2020 Mar 30, 2020

Copy link to clipboard

Copied

I'm happy to report I got it working just before I went to bed last night. Here is the solution in case anyone else runs across the problem. I was using 'textedit' to try and save the .jsx file and on the Mac this does not save it properly with that app. I did research and found I should use theAdobe Extendscript Toolkit CC to create the .jsx file. Because it is no longer supported I needed to find this link on how to locate and install the Toolkit (You MUST have a CC account or it will not show up in Creative Cloud) : 

Adobe Extendscript Toolkit CC download for macOS 10.13.2

 

After installing the toolkit I simply pasted your code into it, it auto formatted everything, save as .jsx and put it in the Photoshop scripts folder, worked like a charm! Thank you so much for all you do expanding the functionality of Photoshop. It will save me tons of work and time!

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 30, 2020 Mar 30, 2020

Copy link to clipboard

Copied

You don't have to use ESTK for this small operation. Just you can do what I suggested by message.

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 ,
Apr 02, 2020 Apr 02, 2020

Copy link to clipboard

Copied

Apple TextEdit has two modes, a plain text mode and a rich text mode, scripts need the plain text mode. You'll likely need to fight with it and manually remove the double .jsx.txt extension and replace with .jsx

 

I personally prefer BBEdit on the Mac over TextEdit for plain text editing, while Atom is another popular choice.

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 ,
Sep 27, 2019 Sep 27, 2019

Copy link to clipboard

Copied

Hi all,

 

Is it possible to make a script or action that both group and name the group the file name at the same time?

Example:

 

Layer01

Layer02

Layer02

 

I want to group them and name each group the layer names.

(exactly the same name as the layer or image)

 

Group name:

Layer01

Layer02

Layer03

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 ,
Sep 27, 2019 Sep 27, 2019

Copy link to clipboard

Copied

Try this:

 

 

#target Photoshop

// community.adobe.com/t5/Photoshop/Action-Script-to-group-layers-and-naming/td-p/10635514

// Select all layers - Except Background "Image" Layer
app.runMenuItem(stringIDToTypeID('selectAllLayers')); 

/*
// Select all layers...
var actionDescriptor = new ActionDescriptor();
var actionReference = new ActionReference();
actionReference.putEnumerated( charIDToTypeID( "Lyr " ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );
actionDescriptor.putReference( charIDToTypeID( "null" ), actionReference );
executeAction( stringIDToTypeID( "selectAllLayers" ), actionDescriptor, DialogModes.NO );
*/

/*
// Select all layers  
// =======================================================  
var idselectAllLayers = stringIDToTypeID( "selectAllLayers" );  
var desc14 = new ActionDescriptor();  
var idnull = charIDToTypeID( "null" );  
var ref8 = new ActionReference();  
var idLyr = charIDToTypeID( "Lyr " );  
var idOrdn = charIDToTypeID( "Ordn" );  
var idTrgt = charIDToTypeID( "Trgt" );  
ref8.putEnumerated( idLyr, idOrdn, idTrgt );  
desc14.putReference( idnull, ref8 );  
executeAction( idselectAllLayers, desc14, DialogModes.NO );  
*/

// community.adobe.com/t5/Photoshop/Group-Selected-Layers/td-p/9983092#10555610
function sTT(v) {return stringIDToTypeID(v)}
(ref = new ActionReference()).putEnumerated
(sTT('document'), sTT('ordinal'), sTT('targetEnum'));
cnt = (lst = executeActionGet(ref).getList(sTT('targetLayersIDs'))).count
for(i = 0; i < cnt;) {
     id = lst.getReference(i++).getIdentifier();
     (ref1 = new ActionReference()).putClass(sTT('layerSection'));
     (dsc1 = new ActionDescriptor()).putReference(sTT('null'), ref1);
     (ref2 = new ActionReference()).putIdentifier(sTT('layer'), id)
     dsc1.putReference(sTT('from'), ref2);
     nme = executeActionGet(ref2).getString(sTT('name'));
     (dsc2 = new ActionDescriptor()).putString(sTT('name'), nme)
     dsc1.putObject(sTT('using'), sTT('layerSection'), dsc2)
     executeAction(sTT('make'), dsc1)
}

 

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 ,
Sep 15, 2021 Sep 15, 2021

Copy link to clipboard

Copied

Hi, thanks for the script! But could you help me? I want to add a mask to the name. To rename the group like this: [slovo:name_layer]

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 ,
Sep 15, 2021 Sep 15, 2021

Copy link to clipboard

Copied

@unsandj 

 

Could you help me to help you by providing a before and after cropped screenshot example of the layers panel? It is not clear to me what you want to do. Thanks!

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
Sep 27, 2019 Sep 27, 2019

Copy link to clipboard

Copied

Hi there,

 

I've found this similar discussion that might be able to help you with your query: Saving multiple files with group name Photoshop

 

Let us know how it goes.

 

Thanks,

Akash

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 03, 2022 Nov 03, 2022

Copy link to clipboard

Copied

Helo!

 

I need script that will make group from a layer and another group from that group with prefixes.  

for example result will look like this:

aleksanderk54154416_0-1667475696156.png

 

is that possible?

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 ,
Nov 03, 2022 Nov 03, 2022

Copy link to clipboard

Copied

@aleksanderk54154416 – Something like this?

 

var layerName = activeDocument.activeLayer.name;
setFromLayer("[Merge]" + layerName);
setFromLayer("[Bone]" + layerName);

function setFromLayer(layNme) {
	function s2t(s) {
		return app.stringIDToTypeID(s);
	}
	var descriptor = new ActionDescriptor();
	var descriptor2 = new ActionDescriptor();
	var reference = new ActionReference();
	var reference2 = new ActionReference();
	reference.putClass( s2t( "layerSection" ));
	descriptor.putReference( s2t( "null" ), reference );
	reference2.putEnumerated( s2t( "layer" ), s2t( "ordinal" ), s2t( "targetEnum" ));
	descriptor.putReference( s2t( "from" ), reference2 );
	descriptor2.putString( s2t( "name" ), layNme );
	descriptor.putObject( s2t( "using" ), s2t( "layerSection" ), descriptor2 );
	executeAction( s2t( "make" ), descriptor, DialogModes.NO );
}

 

A prompt could be added so that you type in the name of the prefix into a GUI, rather than having it hard-coded.

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 03, 2022 Nov 03, 2022

Copy link to clipboard

Copied

It works man! I am going to cry now :))

 

thanx 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
Community Beginner ,
Nov 03, 2022 Nov 03, 2022

Copy link to clipboard

Copied

but, but 🙂 can you make it to work for each layer when selected  multiple layers? 

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 ,
Nov 03, 2022 Nov 03, 2022

Copy link to clipboard

Copied

quote

but, but 🙂 can you make it to work for each layer when selected  multiple layers? 


By @aleksanderk54154416

 

Ah, scope creep!

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 ,
Nov 03, 2022 Nov 03, 2022

Copy link to clipboard

Copied

Try this:

 

#target photoshop

function main() {

    ///// Process selected layers - from jazz-y /////
    var s2t = stringIDToTypeID;
    (r = new ActionReference()).putProperty(s2t('property'), p = s2t('targetLayersIDs'));
    r.putEnumerated(s2t('document'), s2t('ordinal'), s2t('targetEnum'));
    var lrs = executeActionGet(r).getList(p),
        sel = new ActionReference();
    for (var i = 0; i < lrs.count; i++) {
        sel.putIdentifier(s2t('layer'), p = lrs.getReference(i).getIdentifier(s2t('layerID')));
        (r = new ActionReference()).putIdentifier(s2t('layer'), p);
        (d = new ActionDescriptor()).putReference(s2t("target"), r);
        executeAction(s2t('select'), d, DialogModes.NO);
    //////////

        var layerName = activeDocument.activeLayer.name;
        setFromLayer("[Merge]" + layerName);
        setFromLayer("[Bone]" + layerName);

        ///// Functions /////

        function setFromLayer(layNme) {
            function s2t(s) {
                return app.stringIDToTypeID(s);
            }
            var descriptor = new ActionDescriptor();
            var descriptor2 = new ActionDescriptor();
            var reference = new ActionReference();
            var reference2 = new ActionReference();
            reference.putClass(s2t("layerSection"));
            descriptor.putReference(s2t("null"), reference);
            reference2.putEnumerated(s2t("layer"), s2t("ordinal"), s2t("targetEnum"));
            descriptor.putReference(s2t("from"), reference2);
            descriptor2.putString(s2t("name"), layNme);
            descriptor.putObject(s2t("using"), s2t("layerSection"), descriptor2);
            executeAction(s2t("make"), descriptor, DialogModes.NO);
        }
    }
}
app.activeDocument.suspendHistory("Undo Script", "main()");

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 03, 2022 Nov 03, 2022

Copy link to clipboard

Copied

Yesss! Thats it! Thank you! No more scope creeping 🙂

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 ,
May 03, 2023 May 03, 2023

Copy link to clipboard

Copied

LATEST

we made a Photoshop plug-in that can do this. The unlimited version is 12$. 

9729E19A-2C85-4EE3-A516-FAB389BBC75D.png

 

Full Version (12$):
https://exchange.adobe.com/apps/cc/c36e02fb/swift


Trial Version (Limited to 5 Actions):
https://exchange.adobe.com/apps/cc/412c1dcd/swift-trial-version

 

Its also a big help with getting the layers selected.

ACDB94BA-0EEB-49C2-9175-058DE034925B.png

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