splits layers and puts them into groups

Engaged ,
Sep 20, 2022 Sep 20, 2022

Copy link to clipboard

Copied

Greetings to all for the most wonderful forum, which serves many of its followers


I am working on a file with more than 500 layers

 

I want a script that splits layers and puts them into groups based on an input value

For example, I want to set a value for example 50 to choose 50 layers and place them inside a group named with the number of layers
--- Then select all the remaining layers and insert a value for example 30 to choose 30 layers and place them within a group named with the number of layers..... etc.

TOPICS
Actions and scripting , SDK

Views

90

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

correct answers 1 Correct answer

Community Expert , Sep 20, 2022 Sep 20, 2022

@Mohamed Hameed 

You can try the following script

 

deSelectAllLayers();
var _layers = app.activeDocument.artLayers;
var _name = prompt('Enter number : ', '');
if (_name) {
    _groupLength = Number(_name);
    if (!isNaN(_groupLength)) {
        if (_groupLength != 0 && _groupLength <= _layers.length) {
            for (var i = 0; i < _groupLength; i++) {
                selectLayerByID(_layers[i].id, true);
            }
            groupSelectedLayers(_name);
        } else {
            aler
...

Likes

Translate

Translate
Community Beginner ,
Sep 20, 2022 Sep 20, 2022

Copy link to clipboard

Copied

Hello, you can try ActionNodes to create such an action yourself. It's pretty easy.

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
community guidelines
Community Expert ,
Sep 20, 2022 Sep 20, 2022

Copy link to clipboard

Copied

Hi @Mohamed Hameed 

When you say, you set a value 50 to choose 50 layers, what does it means

1. 50 layers alreday selected?

2. you want to select 50 layers. if yes, which 50 layers, first 50 , last 50 or alternative. How you will decide which 50 layers.

 

If you can show some samples that will be helpful for us to guide you in right direction.

 

Best regards

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
community guidelines
Engaged ,
Sep 20, 2022 Sep 20, 2022

Copy link to clipboard

Copied

@Charu Rajput 

To clearly explain what is required
I have a file with for example 500 layers or more and they are all the same size
I want to make groups for the layers, but with different numbers for each group

For example, I want to choose 50 layers and put them in a group named 50 layers
Choose 30 layers and place them in a group named 30 layers

-- As for the selection of layers, the layers are selected from top to bottom..with the exclusion of the layers and groups that have been created

 

Best regards

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
community guidelines
Community Expert ,
Sep 20, 2022 Sep 20, 2022

Copy link to clipboard

Copied

@Mohamed Hameed 

You can try the following script

 

deSelectAllLayers();
var _layers = app.activeDocument.artLayers;
var _name = prompt('Enter number : ', '');
if (_name) {
    _groupLength = Number(_name);
    if (!isNaN(_groupLength)) {
        if (_groupLength != 0 && _groupLength <= _layers.length) {
            for (var i = 0; i < _groupLength; i++) {
                selectLayerByID(_layers[i].id, true);
            }
            groupSelectedLayers(_name);
        } else {
            alert('Either you entered 0 or entered number is higher than the number of layers present in the document');
        }
    } else {
        alert('Enter value is not the number')
    }
}

function groupSelectedLayers(theName) {
    var desc159 = new ActionDescriptor();
    var ref114 = new ActionReference();
    var idlayer = stringIDToTypeID("layer");
    var idordinal = stringIDToTypeID("ordinal");
    var idtargetEnum = stringIDToTypeID("targetEnum");
    var idnull = stringIDToTypeID("null");
    var idname = stringIDToTypeID("name");
    ref114.putEnumerated(idlayer, idordinal, idtargetEnum);
    desc159.putReference(idnull, ref114);
    desc159.putString(idname, "aaa");
    executeAction(stringIDToTypeID("groupLayersEvent"), desc159, DialogModes.NO);
    var desc63 = new ActionDescriptor();
    var ref37 = new ActionReference();
    ref37.putEnumerated(idlayer, idordinal, idtargetEnum);
    desc63.putReference(idnull, ref37);
    var desc64 = new ActionDescriptor();
    desc64.putString(idname, theName);
    desc63.putObject(stringIDToTypeID("to"), idlayer, desc64);
    executeAction(stringIDToTypeID("set"), desc63, DialogModes.NO)
}

function selectLayerByID(index, add) {
    add = undefined ? add = false : add
    var ref = new ActionReference();
    ref.putIdentifier(charIDToTypeID("Lyr "), index);
    var desc = new ActionDescriptor();
    desc.putReference(charIDToTypeID("null"), ref);
    if (add) desc.putEnumerated(stringIDToTypeID("selectionModifier"), stringIDToTypeID("selectionModifierType"), stringIDToTypeID("addToSelection"));
    desc.putBoolean(charIDToTypeID("MkVs"), false);
    try {
        executeAction(charIDToTypeID("slct"), desc, DialogModes.NO);
    } catch (e) {
        alert(e.message);
    }
};

function deSelectAllLayers() {
    var idselectNoLayers = stringIDToTypeID("selectNoLayers");
    var desc26 = new ActionDescriptor();
    var idnull = charIDToTypeID("null");
    var ref3 = new ActionReference();
    var idLyr = charIDToTypeID("Lyr ");
    var idOrdn = charIDToTypeID("Ordn");
    var idTrgt = charIDToTypeID("Trgt");
    ref3.putEnumerated(idLyr, idOrdn, idTrgt);
    desc26.putReference(idnull, ref3);
    executeAction(idselectNoLayers, desc26, DialogModes.NO);
}

 

 

Reference links

https://community.adobe.com/t5/photoshop-ecosystem-discussions/photoshop-script-how-to-select-multi-...

 

https://community.adobe.com/t5/photoshop-ecosystem-discussions/how-can-i-deselect-all-layers/td-p/96....

 

Note: The above script will not take care of nested structure of the layers.

 

Best regards

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
community guidelines
Engaged ,
Sep 20, 2022 Sep 20, 2022

Copy link to clipboard

Copied

@Charu Rajput 

majesty, grandeur, grandeur
How great you are and how clever you are
Thank you for your interest and for helping me

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
community guidelines
Community Expert ,
Sep 20, 2022 Sep 20, 2022

Copy link to clipboard

Copied

@Charu Rajput – Excellent work!

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
community guidelines
Community Expert ,
Sep 21, 2022 Sep 21, 2022

Copy link to clipboard

Copied

LATEST

@Stephen_A_Marsh - It is only possible with the support of all of us.

Best regards

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