Copy link to clipboard
Copied
Hello!
Here is my situation, I'd like to be able to launch a script for selecting all the layers with the name A
within my layer stack:
I've already seen several posts speaking about the same question, but for some reason I'm not able to use the scripts who have been shared. I'm using ExtendScript Toolkit CS5 with Photoshop CC 2019, could it be the reason?
Thanks!
Try this:
#target photoshop
var doc = activeDocument;
var curLayer = doc.activeLayer;
var layName = curLayer.name;
var selcList = new Array();
var layerSets = 0
try{doc.backgroundLayer}
catch(e){layerSets=1}
var fullList = getLayerSetsData ();
for(var i=0;i<fullList.length;i++){
if(fullList[i].name.toLowerCase() == layName.toLowerCase()){
selcList.push(fullList[i].id)
}
}
if(selcList.length>1){multiSelectByIDs (selcList)}
else{alert('There are no duplicate layer names
...
Copy link to clipboard
Copied
Since it looks like your file has several different layer names that are duplicates, how to you want to select just one set of them - by using the current selected layer?
Copy link to clipboard
Copied
Well, the idea would be to be able to select all the layers with the same name, so that I can move them into the same folder at the same time (the file I'm working on currently contains hundreds of layers, and it's impossible to select rapidly all the layers with the same name).
Are you saying it sounds impossible to do that script (sorry I'm not a programer)?
I tried to create a script manually on Photoshop but it selects systematically the layer A at the bottom of the stack and only this one.
Thanks for your help!
Copy link to clipboard
Copied
No, it's possible to get all layers with duplicate name, just wondering what exactly you want.
Copy link to clipboard
Copied
Ok! Let me explain step by step:
Whatever layer is selected in the layer stack, I like to be able to select all the layers with the same name in the layer stack, thanks to a script button, and that's all.
1:
2: I press the script (than I'll name "Select A") and it selects all the other layers named A:
And then, this shouldn't be included in the script because I'm using a timeline in Photoshop,
putting all those layers in the folder at the bottom:
And I will do the same thing with an other script but for B, and then for C and so forth.
Copy link to clipboard
Copied
Okay, that's what I thought would make more sense than selecting any layers that have the same name, like all the A's and B's in your example. It would be easier for just one set at a time.
Copy link to clipboard
Copied
Try this:
#target photoshop
var doc = activeDocument;
var curLayer = doc.activeLayer;
var layName = curLayer.name;
var selcList = new Array();
var layerSets = 0
try{doc.backgroundLayer}
catch(e){layerSets=1}
var fullList = getLayerSetsData ();
for(var i=0;i<fullList.length;i++){
if(fullList[i].name.toLowerCase() == layName.toLowerCase()){
selcList.push(fullList[i].id)
}
}
if(selcList.length>1){multiSelectByIDs (selcList)}
else{alert('There are no duplicate layer names')};
function doesIdExists( id ){// function to check if the id exists
var res = true;
var ref = new ActionReference();
ref.putIdentifier(charIDToTypeID('Lyr '), id);
try{var desc = executeActionGet(ref)}catch(err){res = false};
return res;
}
function multiSelectByIDs(ids) {
if( ids.constructor != Array ) ids = [ ids ];
var layers = new Array();
var id54 = charIDToTypeID( "slct" );
var desc12 = new ActionDescriptor();
var id55 = charIDToTypeID( "null" );
var ref9 = new ActionReference();
for (var i = 0; i < ids.length; i++) {
if(doesIdExists(ids[i]) == true){// a check to see if the id stil exists
layers[i] = charIDToTypeID( "Lyr " );
ref9.putIdentifier(layers[i], ids[i]);
}
}
desc12.putReference( id55, ref9 );
var id58 = charIDToTypeID( "MkVs" );
desc12.putBoolean( id58, false );
executeAction( id54, desc12, DialogModes.NO );
}
function getLayerSetsData()
{
//var count = 0;//set counter for multi-dimensional array
var lyrSets = [];
while (true)
{
ref = new ActionReference();
ref.putIndex(charIDToTypeID('Lyr '), layerSets);
try
{var d1 = executeActionGet(ref)}
catch (err){
break;
};
var c2t = function (s){return app.charIDToTypeID(s);};
var s2t = function (s){return app.stringIDToTypeID(s);};
var lyrSet = {};
lyrSet.type = d1.getInteger(s2t("layerKind"));
lyrSet.name = d1.getString(c2t("Nm "));
lyrSet.id = d1.getInteger(s2t("layerID"));
lyrSets.push(lyrSet);
layerSets++;
};
return lyrSets;
};
Copy link to clipboard
Copied
Thank you very much Chuck!
I just tried it and I get the message "there are no duplicate layer names"
Did I make something wrong?
Copy link to clipboard
Copied
Oh, actually it works fine!!! I haven't selected any of the layers duplicated (like A or B) but
I was on C (which was the only layer with that name - the others were copy C, copy2 C, etc).
THANKS SO MUCH CHUCK!
Copy link to clipboard
Copied
Glad it's working for you.
Copy link to clipboard
Copied
I know this is an old post, any chance we can do it REGEX. Pluging works really good on same layer names. But you normaly make a copy of the layer to control PSB and creates a copy example from "Logo Smart" to "Logo Smart copy 31"
I tried to read your code but didn't understand how its working. So if we can have 1 that gets all the layers with Same Name, having any other text on layers. a type of REGEX thing, would appreciate.
Copy link to clipboard
Copied
Wouldn’t changing
if(fullList[i].name.toLowerCase() == layName.toLowerCase()){
to
if(fullList[i].name.toLowerCase().match(layName.toLowerCase()) != -1){
suffice?
Copy link to clipboard
Copied
Thanks for the quick replay and taking your time to help.
Your code is selecting all layers strangely. 😞
Copy link to clipboard
Copied
What code exactly?
I was referring to a line in @Chuck Uebele ’s Script.
Copy link to clipboard
Copied
One can avoid the adding of »copy x« to duplicated Layers’ names by unchecking »Add "copy" to Copied Layers and Groups«.
Copy link to clipboard
Copied
Thanks this helps alot for future PS works. TY.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Hi Pfaffenbichler!
Your script also worked super well, thanks!!
It upgrades the Chuck's one, that's great!