Sort Layer select

Participant ,
May 05, 2021 May 05, 2021

Copy link to clipboard

Copied

I have 5 layers. In this scripts First 5 Layer,4Layers,3Layers,2Layers,1Layers, But i want 1Layer,2Layers,3Layers,4Layers,5Layers etc. Please Accendring ther layer

 

var newName =("layer name", "Layer");

var docRef = app.activeDocument;

var layers = getSelectedLayers(app.activeDocument);
for (var i = 0; i <layers.length; i ++){
layers[i].selected = true;
docRef.activeLayer = layers[i];
alert(docRef.activeLayer.name);
}

function getSelectedLayers(){
var idGrp = stringIDToTypeID( "groupLayersEvent" );
var descGrp = new ActionDescriptor();
var refGrp = new ActionReference();
refGrp.putEnumerated(charIDToTypeID( "Lyr " ),charIDToTypeID( "Ordn" ),charIDToTypeID( "Trgt" ));
descGrp.putReference(charIDToTypeID( "null" ), refGrp );
executeAction( idGrp, descGrp, DialogModes.ALL );
var resultLayers=new Array();
for (var ix=0;ix<app.activeDocument.activeLayer.layers.length;ix++){resultLayers.push(app.activeDocument.activeLayer.layers[ix])}
var id8 = charIDToTypeID( "slct" );
var desc5 = new ActionDescriptor();
var id9 = charIDToTypeID( "null" );
var ref2 = new ActionReference();
var id10 = charIDToTypeID( "HstS" );
var id11 = charIDToTypeID( "Ordn" );
var id12 = charIDToTypeID( "Prvs" );
ref2.putEnumerated( id10, id11, id12 );
desc5.putReference( id9, ref2 );
executeAction( id8, desc5, DialogModes.NO );
return resultLayers;
}

TOPICS
Actions and scripting

Views

1.2K

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

Can be used

layers.reverse();

 

or you can change the order of this loop

for (var ix = app.activeDocument.activeLayer.layers.length-1; ix >= 0; ix--)

 

or this

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

 

choose...

Likes

Translate

Translate
Community Expert ,
May 05, 2021 May 05, 2021

Copy link to clipboard

Copied

Can be used

layers.reverse();

 

or you can change the order of this loop

for (var ix = app.activeDocument.activeLayer.layers.length-1; ix >= 0; ix--)

 

or this

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

 

choose...

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

Copy link to clipboard

Copied

Thanks r-bin, Thanku so much you are great. I glad to you

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
LEGEND ,
Sep 08, 2021 Sep 08, 2021

Copy link to clipboard

Copied

activeDocument.layers.reserve()

does not work until used as:

[].slice.call(activeDocument.layers).reverse()

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

Copy link to clipboard

Copied

why is used [].slice.call @Kukurykus 

[].slice.call(activeDocument.layers).reverse()

 

 

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
LEGEND ,
Sep 08, 2021 Sep 08, 2021

Copy link to clipboard

Copied

It duplicates native Photoshop layers array to regular kind of array. (Avoid my name).

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

Copy link to clipboard

Copied

This is not used here, nor is it suggested to use.

 

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
LEGEND ,
Sep 08, 2021 Sep 08, 2021

Copy link to clipboard

Copied

I meant this part in your post:

 

Can be used

layers.reverse();

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

Copy link to clipboard

Copied

quote

I meant this part in your post:

 

Can be used

layers.reverse();


By @Kukurykus

 

So what? What does activeDocument.layers have to do with it?

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
LEGEND ,
Sep 08, 2021 Sep 08, 2021

Copy link to clipboard

Copied

I wanted to be precise, so instead of layers I used activeDocument.layers, isn't it the same?

 

Okay, probably you meant something more complex than originally I thought. To use:

layers.reverse()

instead of:

for(var i = 0; i <layers.length; i ++){
	layers[i].selected = true;
	docRef.activeLayer = layers[i];
	alert(docRef.activeLayer.name);
}

 

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

Copy link to clipboard

Copied

Am Also saying this is not used here ?

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
Contributor ,
Aug 17, 2022 Aug 17, 2022

Copy link to clipboard

Copied

LATEST

How To layer serial wise name position set

https://youtu.be/I7IW2YYWBLs

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

Save time with Adobe Express quick actions