• 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.4K

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
Valorous Hero ,
May 04, 2021 May 04, 2021

Copy link to clipboard

Copied

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"));

        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); }
    }

 

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

Copy link to clipboard

Copied

This is right ,Please check it

 

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); }
}


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;
};

 

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

Copy link to clipboard

Copied

Please Add The Rename Each Layer From Left to right like layer1,layer2,layer3 etc

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

Copy link to clipboard

Copied

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

Copy link to clipboard

Copied

Yes, sort of like that. But your code is not complete as in the first post. It won't work.

 

There I have a mistake !!!!!!!!!.

Correct

return l1> l2;

to the

return l1 - l2;

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

Copy link to clipboard

Copied

Yes, It's perfect working, But one thing I want to this right to left, You have button to top,

Please see the image

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

Copy link to clipboard

Copied

Modify the script, Please see the image below

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

Copy link to clipboard

Copied

OK

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

var r = new ActionReference();
r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("width"));
r.putEnumerated(stringIDToTypeID("document"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
var doc_w = executeActionGet(r).getUnitDoubleValue(stringIDToTypeID("width"));

var r = new ActionReference();
r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("height"));
r.putEnumerated(stringIDToTypeID("document"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
var doc_h = executeActionGet(r).getUnitDoubleValue(stringIDToTypeID("height"));

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 t1 = b1.getUnitDoubleValue(stringIDToTypeID("top"));
        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 t2 = b2.getUnitDoubleValue(stringIDToTypeID("top"));
        var l2 = b2.getUnitDoubleValue(stringIDToTypeID("left"));

        t1 = 100-Math.round(doc_h/t1)*100;
        t2 = 100-Math.round(doc_h/t2)*100;

        var x1 = l1 + t1*doc_w;
        var x2 = l2 + t2*doc_w;

        return x1 - x2;
        }
    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
Participant ,
May 04, 2021 May 04, 2021

Copy link to clipboard

Copied

Yes, Thanku so much But entire left right now, Please see the image below,

Please modify 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
Valorous Hero ,
May 04, 2021 May 04, 2021

Copy link to clipboard

Copied

Where did you see there from left to right and from top to bottom? I see no logic.

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

Copy link to clipboard

Copied

Everyting is ok, but one thing is entire left to right , Please see the image...

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

Copy link to clipboard

Copied

I do not understand you. Be clearer.

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

Copy link to clipboard

Copied

Yes everything is fine, But I will put on 12x36 page. The script is entire left so I with 12x18 page is good working but 12x36 page is enitre left so

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

Copy link to clipboard

Copied

Post the PSD with the problem. I'll see.

And explain what you are doing, which layers you are selecting.

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

Copy link to clipboard

Copied

I have put on 12x36 page, The script is entire left Please check it.

1:- Create 12x36 Page

2:- Create 8 Layer

3:- Run the Script

4:- The result is entire left to right.

 

12x18 Page is good working and 4 layer also good working, Just 8 Layer to entire left to right,

Please see the image below

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

Copy link to clipboard

Copied

I have given the the psd below please check it, The psd entire left to right, I wish see image below right

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

Copy link to clipboard

Copied

Did you understand that

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

Copy link to clipboard

Copied

Did you check it , let me know Did you understand 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
Valorous Hero ,
May 04, 2021 May 04, 2021

Copy link to clipboard

Copied

Hey people.

Does anyone understand what he wants.

crazy-face.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
Participant ,
May 04, 2021 May 04, 2021

Copy link to clipboard

Copied

I have explain to image, please see the image concentrate.

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

Copy link to clipboard

Copied

Thanku so much, I expect you can do it, And I hope you can easily understand after saw the image.

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

Copy link to clipboard

Copied

Have seen it 100 times. Explain the logic. Or do you always have only eight layers arranged this way? This is not from left to right, but some kind of сикось-накось (google could not translate : ).

 

 

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

Copy link to clipboard

Copied

Thanks r-bin I have modify and Now is working perfect. Thanku so much r-bin 

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

Copy link to clipboard

Copied

Hello Eveyone, This script is perfect working, It is select Bottom to Top Layer.

But I want to Select Top to Bottom in Selected Layer in PS Script

sg1.jpg

sg2.jpg

Here is script , Please modify the script ?

May 04, 2021

 

 

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
Community Expert ,
Sep 09, 2021 Sep 09, 2021

Copy link to clipboard

Copied

Have you tried reversing the order you process layer ID?

//for each id in the list
for (var i = 0; i < ids.length; i++)

someting like:

 

for (var i = ids.length;  i  >=  0;  i--)

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