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

Could You Select All Layers Sequentially

Participant ,
Jan 06, 2021 Jan 06, 2021

Copy link to clipboard

Copied

I Wish Select All Layer One By One Sequentially. Like 1,2,3,4 so on. 

Thanks in Advance

Capture.JPG

TOPICS
Actions and scripting

Views

7.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 3 Correct answers

Community Expert , Jan 10, 2021 Jan 10, 2021

Presuming that a layer has a unique name (otherwise the first layer with the name will be targeted, which may not be the one you require):

 

 

var selectLayer1 = app.activeDocument.artLayers.getByName("Layer 1");
app.activeDocument.activeLayer = selectLayer1;

 

 

or

 

 

app.activeDocument.activeLayer = app.activeDocument.layers["Layer 1"];

 

 

 

The layers collection can also be used, it starts the indexing at zero, so the 8th layer from the top would be #7:

 

 

var selectLayer = app.activeDocum
...

Votes

Translate

Translate
Valorous Hero , May 04, 2021 May 04, 2021

In your script, right after the line

var ids = getLayersIDs (); // getting ids of selected layers

 

paste this code:

ids.sort(cmp);
function cmp(a, b)
    {
    try {
        var r = new ActionReference();
        r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("bounds"));
        r.putIdentifier(stringIDToTypeID("layer"), a);
        var b1 = executeActionGet(r).getObjectValue(stringIDToTypeID("bounds"));

        var l1 = b1.getUnitDoubleValue(stringIDToTypeID("left"));

       
...

Votes

Translate

Translate
Community Expert , May 06, 2021 May 06, 2021

Your first screen shot showed that you wanted the artboard numbered top to bottom then left to right, which the previous script that I posted did. You're second screen shot shows left to right then top to bottom. So this script does that:

 

#target photoshop
var doc = activeDocument;
var artArray = [];
var count = 0;
for(var i=0;i<doc.layers.length;i++){
    doc.activeLayer = doc.layers[i];
    if(isArtBoard ()){
        var dimArt = getArtboardDimensions ()
        artArray.push([dimArt[0],dimA
...

Votes

Translate

Translate
Adobe
LEGEND ,
May 05, 2021 May 05, 2021

Copy link to clipboard

Copied

Wow! There's 3rd one same thread? What a mess. If you're moderator combine them into one.

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 ,
Oct 09, 2021 Oct 09, 2021

Copy link to clipboard

Copied

Hello Everyone I found the script From MXKS, But I need modify the script. Anyone could you help me. I am new Of PS Script. I have seached on google but can't find.

The Script was created By @r-bin, I need Serial Number wise to Layers. For Better Understand I posted the image. 

If I am say something wrong, extremly sorry because i am new here..

ss.jpg

Here is script For Serial Number Wise Layers

 

var newName = "Layer";
var ids = getLayersIDs(); // getting ids of selected layers

ids.sort(cmp);
function cmp(a, b)
    {
    try {
        var r = new ActionReference();
        r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("bounds"));
        r.putIdentifier(stringIDToTypeID("layer"), a);
        var b1 = executeActionGet(r).getObjectValue(stringIDToTypeID("bounds"));

        var l1 = b1.getUnitDoubleValue(stringIDToTypeID("left"));

        var r = new ActionReference();
        r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("bounds"));
        r.putIdentifier(stringIDToTypeID("layer"), b);
        var b2 = executeActionGet(r).getObjectValue(stringIDToTypeID("bounds"));

        var l2 = b2.getUnitDoubleValue(stringIDToTypeID("left"));

        return l1 > l2;
        }
    catch (e) { throw(e); }
    }


//for each id in the list
for (var i = 0; i < ids.length; i++)
{
// select the layer first (well, artboard in this case)
selectById(ids[i]);

//rename it to "my name 1", "my name 2", etc
activeDocument.activeLayer.name = newName + " " + (i + 1);
}

// this will get IDs of selected layers/groups/artboards
function getLayersIDs()
{
var lyrs = [];
var lyr;
var ref = new ActionReference();
var desc;
var tempIndex;
var ref2;

ref.putProperty(stringIDToTypeID("property"), stringIDToTypeID("targetLayers"));
ref.putEnumerated(charIDToTypeID('Dcmn'), charIDToTypeID('Ordn'), charIDToTypeID('Trgt'));

var targetLayers = executeActionGet(ref).getList(stringIDToTypeID("targetLayers"));
for (var i = 0; i < targetLayers.count; i++)
{
tempIndex = 0;
ref2 = new ActionReference();
try
{
activeDocument.backgroundLayer;
ref2.putIndex(charIDToTypeID('Lyr '), targetLayers.getReference(i).getIndex());
try
{
desc = executeActionGet(ref2);
tempIndex = desc.getInteger(stringIDToTypeID("itemIndex")) - 1;
}
catch (e)
{
tempIndex = 0;
}
}
catch (o)
{
ref2.putIndex(charIDToTypeID('Lyr '), targetLayers.getReference(i).getIndex() + 1);
desc = executeActionGet(ref2);
tempIndex = desc.getInteger(stringIDToTypeID("itemIndex"));
}

lyrs.push(desc.getInteger(stringIDToTypeID("layerID")));
}

return lyrs;
};

// this will select a layer by ID
function selectById(id)
{
var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putIdentifier(charIDToTypeID('Lyr '), id);
desc1.putReference(charIDToTypeID('null'), ref1);
executeAction(charIDToTypeID('slct'), desc1, DialogModes.NO);
};

 

 

Anyone can't reply i can't resove my 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
Valorous Hero ,
Oct 10, 2021 Oct 10, 2021

Copy link to clipboard

Copied

quote

Anyone can't reply i can't resove my problem 


By @Sriya69

 

Your problem is not clear.
 
P.S. By the way, there is a mistake in the code. You cannot use "return l1> l2". It is corrected in the original code.

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 ,
Oct 10, 2021 Oct 10, 2021

Copy link to clipboard

Copied

Sorry, I have not seen original code, However I run the script in PS (But It's not perfect) ....

For Example I have attached the image ------ 

I am trying to Serial Number of layer in my own templates.. Original Code have instead of return l1 - l2;

My Problem is Seial Number wise Layer in my own templates, Here is posted 2images. 

Could you compare the image 1 and image 2 For Better Understand..

sn1.jpg

 

Image 2

sn.jpg

 

Original Code is Here

var newName = "Layer";
var ids = getLayersIDs(); // getting ids of selected layers

ids.sort(cmp);
function cmp(a, b)
    {
    try {
        var r = new ActionReference();
        r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("bounds"));
        r.putIdentifier(stringIDToTypeID("layer"), a);
        var b1 = executeActionGet(r).getObjectValue(stringIDToTypeID("bounds"));

        var l1 = b1.getUnitDoubleValue(stringIDToTypeID("left"));

        var r = new ActionReference();
        r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("bounds"));
        r.putIdentifier(stringIDToTypeID("layer"), b);
        var b2 = executeActionGet(r).getObjectValue(stringIDToTypeID("bounds"));

        var l2 = b2.getUnitDoubleValue(stringIDToTypeID("left"));

        return l1 - l2;
        }
    catch (e) { throw(e); }
    }


//for each id in the list
for (var i = 0; i < ids.length; i++)
{
// select the layer first (well, artboard in this case)
selectById(ids[i]);

//rename it to "my name 1", "my name 2", etc
activeDocument.activeLayer.name = newName + " " + (i + 1);
}

// this will get IDs of selected layers/groups/artboards
function getLayersIDs()
{
var lyrs = [];
var lyr;
var ref = new ActionReference();
var desc;
var tempIndex;
var ref2;

ref.putProperty(stringIDToTypeID("property"), stringIDToTypeID("targetLayers"));
ref.putEnumerated(charIDToTypeID('Dcmn'), charIDToTypeID('Ordn'), charIDToTypeID('Trgt'));

var targetLayers = executeActionGet(ref).getList(stringIDToTypeID("targetLayers"));
for (var i = 0; i < targetLayers.count; i++)
{
tempIndex = 0;
ref2 = new ActionReference();
try
{
activeDocument.backgroundLayer;
ref2.putIndex(charIDToTypeID('Lyr '), targetLayers.getReference(i).getIndex());
try
{
desc = executeActionGet(ref2);
tempIndex = desc.getInteger(stringIDToTypeID("itemIndex")) - 1;
}
catch (e)
{
tempIndex = 0;
}
}
catch (o)
{
ref2.putIndex(charIDToTypeID('Lyr '), targetLayers.getReference(i).getIndex() + 1);
desc = executeActionGet(ref2);
tempIndex = desc.getInteger(stringIDToTypeID("itemIndex"));
}

lyrs.push(desc.getInteger(stringIDToTypeID("layerID")));
}

return lyrs;
};

// this will select a layer by ID
function selectById(id)
{
var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putIdentifier(charIDToTypeID('Lyr '), id);
desc1.putReference(charIDToTypeID('null'), ref1);
executeAction(charIDToTypeID('slct'), desc1, DialogModes.NO);
};

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
Valorous Hero ,
Oct 10, 2021 Oct 10, 2021

Copy link to clipboard

Copied

quote
....
By @Sriya69

 

OK. Try using this comparison function. 

 

function cmp(a, b)
    {
    try {
        var ref = new ActionReference();
        ref.putProperty(stringIDToTypeID("property"), stringIDToTypeID("bounds"));
        ref.putIdentifier(stringIDToTypeID("layer"), a);
        var bn = executeActionGet(ref).getObjectValue(stringIDToTypeID("bounds"));

        var l1 = bn.getUnitDoubleValue(stringIDToTypeID("left"));
        var r1 = bn.getUnitDoubleValue(stringIDToTypeID("right"))
        var t1 = bn.getUnitDoubleValue(stringIDToTypeID("top"));
        var b1 = bn.getUnitDoubleValue(stringIDToTypeID("bottom"))

        var x1 = (r1+l1)/2;
        var y1 = (b1+t1)/2;

        var ref = new ActionReference();
        ref.putProperty(stringIDToTypeID("property"), stringIDToTypeID("bounds"));
        ref.putIdentifier(stringIDToTypeID("layer"), b);
        var bn = executeActionGet(ref).getObjectValue(stringIDToTypeID("bounds"));

        var l2 = bn.getUnitDoubleValue(stringIDToTypeID("left"));
        var r2 = bn.getUnitDoubleValue(stringIDToTypeID("right"))
        var t2 = bn.getUnitDoubleValue(stringIDToTypeID("top"));
        var b2 = bn.getUnitDoubleValue(stringIDToTypeID("bottom"))

        var x2 = (r2+l2)/2;
        var y2 = (b2+t2)/2;

        var l = l1>l2?l1:l2;
        var r = r1<r2?r1:r2;

        if (x1 >= l && x1 <= r && x2 >= l && x2 <= r ) // same column, i.e. through the layers you can spend a vertical direct
            {
            return y1 - y2;
            }
        else
            {
            return x1 - x2;
            }
        }
    catch (e) { throw(e); }
    }

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 ,
Oct 10, 2021 Oct 10, 2021

Copy link to clipboard

Copied

Thanku so much this is perfect working siir ( You have modify the function) 

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 31, 2022 Aug 31, 2022

Copy link to clipboard

Copied

This script is doing less new in Photoshop C3, is this script possible and will reduce it in CS3 ?

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 02, 2023 Feb 02, 2023

Copy link to clipboard

Copied

unecessary redirect to another thread removed.

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 ,
May 30, 2021 May 30, 2021

Copy link to clipboard

Copied

 

EDIT: 29th December 2021:

I have updated my "Active Layer Inspector" script to v1.7:

 

/////////// ACTIVE LAYER INSPECTOR v1.7, 29th December 2021 ///////////
/////////////// Displays info about the current layer ///////////////

/* https://community.adobe.com/t5/photoshop/could-you-select-all-layers-sequentially/m-p/11741392 */

/* Name = Not unique */
/* itemIndex = Changes with layer addition/removal, Background layer index starts at 0 - no Background starts at 1 */
/* layer.id = Unique, Static */

#target photoshop

try {
    var savedRuler = app.preferences.rulerUnits;
    app.preferences.rulerUnits = Units.PIXELS;

    var doc = app.activeDocument;
    var docLayer = doc.activeLayer;
    var layerName = docLayer.name;
    var itemIndex = getActiveLayerIndex();
    var layerID = docLayer.id;
    var typeName = docLayer.typename;
    var Kind = docLayer.kind;
    var bgLayer = docLayer.isBackgroundLayer;
    var Parent = docLayer.parent;
    var clipMask = docLayer.grouped;

    /* https://community.adobe.com/t5/photoshop/find-out-the-size-and-position-of-an-object-in-a-layer/td-p/12057799 */
    var bounds = activeDocument.activeLayer.bounds;

    alert('ACTIVE LAYER INSPECTOR - v1.5' + '\r' + 'Layer Name: ' + layerName + '\r' + 'Layer Item Index #: ' + itemIndex + '\r' + 'Layer ID #: ' + layerID + '\r' + 'Layer Type: ' + typeName + '\r' + 'Layer Kind: ' + Kind + '\r' + 'Parent: ' + Parent + '\r' + 'isBackgroundLayer: ' + bgLayer + '\r' + 'Grouped: ' + clipMask +'\n' + 'Layer Bounds -' + '\r' + 'X: ' + bounds[0] + ', Y: ' + bounds[1] + '\n' + 'Width: ' + (bounds[2] - bounds[0]) + ', Height: ' + (bounds[3] - bounds[1]));
    
    app.preferences.rulerUnits = savedRuler;

    function getActiveLayerIndex() {
        /* https://github.com/Paul-Riggott/PS-Scripts/blob/master/getLayersetLayerIDs.jsx */
        var ref = new ActionReference();
        ref.putEnumerated(charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt'));
        try {
            activeDocument.backgroundLayer;
            return executeActionGet(ref).getInteger(charIDToTypeID("ItmI")) - 1;
        } catch (e) {
            return executeActionGet(ref).getInteger(charIDToTypeID("ItmI"));
        }
    };

}
catch (e) {
}

 

 

ALI-v15.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
Community Expert ,
Sep 10, 2021 Sep 10, 2021

Copy link to clipboard

Copied

Hello, the merging of the threads made it very difficult to follow.

@MXKS could you maybe post the explanation in your native language?

 

The way I understand, you would like to have a script that would 1) name layers from a given order 2) change the layers position from top to bottom?

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

Copy link to clipboard

Copied

quote

Hello, the merging of the threads made it very difficult to follow.

@MXKS could you maybe post the explanation in your native language?

 

The way I understand, you would like to have a script that would 1) name layers from a given order 2) change the layers position from top to bottom?


By @PECourtejoie

 

 

Truth be told, it was a dog's breakfast before then, perhaps even from the start? This is a serial issue with almost every topic created by MXKS. For what it is worth, my vote would be to press the reset button (lock the thread and start again).

 

I also agree that the online translator used by the OP is not helping, posting in their native language and stating in English which language this is would help interested parties to use their own preferred translation services to read the question. That being said, translation is only part of the problem. Clear concise step by step points stating the objective and steps, with screenshots with useful annotations would surely help from the very start. 

 

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
Participant ,
Sep 10, 2021 Sep 10, 2021

Copy link to clipboard

Copied

For Better Under I posted the image @Stephen_A_Marsh

 

Step 1:- I have 4Layers Of Squre.

Step 2:- I want to Select top to bottom like second image in scripts

 

Here is script >..

Sep 09, 2021

 

 

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
Participant ,
Sep 10, 2021 Sep 10, 2021

Copy link to clipboard

Copied

@PECourtejoie Yes, I want top to bottom 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 10, 2021 Sep 10, 2021

Copy link to clipboard

Copied

You then need to change the sorting of the selected layers by their position over the canvas.  Right now the sort is  from the left to right and bottom to top.  You want the sort to be from left to  right  and top to  bottom. You need to modify script's  Sort compare function to sort the array of selected layer in the order you want to rename them in.

 

You need to modify the scripts code in  "function cmp(a, b)" 

 

I do not know how to do that. I do not understand how   javascript  .sort() method works.   When I change it to.

 

function cmp(a, b)
    {
    try {
        var r = new ActionReference();
        r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("bounds"));
        r.putIdentifier(stringIDToTypeID("layer"), a);
        var b1 = executeActionGet(r).getObjectValue(stringIDToTypeID("bounds"));

        var l1 = b1.getUnitDoubleValue(stringIDToTypeID("left"));

        var r = new ActionReference();
        r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("bounds"));
        r.putIdentifier(stringIDToTypeID("layer"), b);
        var b2 = executeActionGet(r).getObjectValue(stringIDToTypeID("bounds"));

        var l2 = b2.getUnitDoubleValue(stringIDToTypeID("left"));

		return l1 + l2;
        }
    catch (e) { throw(e); }
    }

 

The layers were sorted into the order I populated the template which surprised me I expected the center image would be sorted to the middle of the group.  I clearly do not know how sort works.  My change may have just killed the sort the layer array order was not changed.  Layer were renamed layer stack order as shown.  I have no idea what the function should return to .sort() its time to hits the references books for me. I know it should retun an indicator   yes or no to change order.

Capture.jpg

JavaScript Array sort: Sorting Array Elements 

JJMack

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
Participant ,
Sep 10, 2021 Sep 10, 2021

Copy link to clipboard

Copied

Yesn But I don't know how to modify the "function cmp(a, b)" 

Could you mofidy the script please @JJMack 

Lots of time waste for me just one thing please solve the 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
Community Expert ,
Sep 10, 2021 Sep 10, 2021

Copy link to clipboard

Copied

So now that a read a bit about sort,  I see this script only sort layers on their  left bounds  it did not also compare the layers vertical top bounds.  So the sort in this script to need to  have logic add to also compare the layers vertical top so layers with the same left edge bounds will also be sort relative to their top bounds.   You are the one that want this..  You should modify this script to work the ways you want it to.  The problem is you feel the is a wast of your time. So do it manually.  Its not something I want to do. Your wasting my time.

JJMack

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
Participant ,
Sep 10, 2021 Sep 10, 2021

Copy link to clipboard

Copied

No, Eveyone are want this, I don't know how to logic in ps script

Everyone can't solve the problem for one thing(top to botton select layer)

@JJMack 

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

Copy link to clipboard

Copied

You are wrong I do not want this script.  Why would the Queen of England want any Photoshop script.  It is not a problem I see no reasons why a script can not sort layers by location both horizontally and vertically. Many layers can have the same origin. Do you want these the have the same names or just ones that have identical bounds. You seem to be the only one that want this script.  If everyone wants this  script someone would have programmed it and made it available for a price or free.   The thing is only targeted layers are renamed and  if you run the script more then once on a document to rename a different set of layers the script will create duplicate layer names.  Why do you want this script.  If you do not how to use logic in Photoshop scripting  you need to learn how to.  You are not going to be able to create your custom scripts without using logic.  You should stick to actions  for automating  things in Photoshop, Action can not have logic  except for a conditionals steps and there  is just a small set of condition that can be tested.

image.png

 

However, logic is required to do what you want to do.

JJMack

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 ,
Jun 11, 2023 Jun 11, 2023

Copy link to clipboard

Copied

hi sir im new here please help me.

i just want a photoshop script for auto fill image Sequentially in selected layers.

please help....

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 ,
Jun 12, 2023 Jun 12, 2023

Copy link to clipboard

Copied

IMG_20230612_153911.jpghi sir i just want a photoshop script, i want to first select all 8 layers 

and then run script and thet below imagege is automatically fill all 

8 layers sequence wise if is it possible then any body can help me. 

 

 

 

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 ,
Jun 12, 2023 Jun 12, 2023

Copy link to clipboard

Copied

Please post the template file or at least meaningful screenshots – so far it is not possible to see whether you set up Smart Objects or not. 

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 ,
Jun 13, 2023 Jun 13, 2023

Copy link to clipboard

Copied

LATEST

hi sir i want image fill with smart object please help me

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