Hi,
Im trying to figure out a way to select multiple layers all with the same name. For example select all layers in the current doc named "Links"
is this possible?
So far all I can do is select 1 of those layers not all of them.
Select multiple layers
-
Paul MR
Select multiple layers
This shoul do it...
Code: Select all#target photoshop
app.bringToFront();
main();
function main(){
if(!documents.length) return;
var selectedLayers = getNamesPlusIDs();
var win = new Window( 'dialog' );
win.p1= win.add("panel", undefined, undefined, {borderStyle:"black"});
win.g1 = win.p1.add('group');
win.g1.orientation = "row";
win.title = win.g1.add('statictext',undefined,'Select Layers by Name');
win.title.alignment="fill";
win.title.graphics.font = ScriptUI.newFont("Georgia","BOLDITALIC",20);
win.g5 =win.p1.add('group');
win.g5.orientation = "column";
win.g5.alignChildren='left';
win.g5.spacing=10;
win.g5.cb1 = win.g5.add('checkbox',undefined,'Case sensitive');
win.g5.cb1.value=true;
win.g5.st1 = win.g5.add('statictext',undefined,'Layer name(s) to select');
win.g5.et1 = win.g5.add('edittext');
win.g5.et1.preferredSize=[250,20];
win.g10 =win.p1.add('group');
win.g10.orientation = "row";
win.g10.alignment='center';
win.g10.spacing=10;
win.g10.bu1 = win.g10.add('button',undefined,'Select Layer(s)');
win.g10.bu1.preferredSize=[110,30];
win.g10.bu2 = win.g10.add('button',undefined,'Cancel');
win.g10.bu2.preferredSize=[110,30];
win.g10.bu1.onClick=function(){
if(win.g5.et1.text == ''){
alert("No layer name has been entered!");
return;
}
win.close(0);
var layersFound = new Array();
for( var s in selectedLayers){
if(win.g5.cb1.value){
if(selectedLayers[s][1].toString() == win.g5.et1.text) layersFound.push(selectedLayers[s][0]);
}else{
if(selectedLayers[s][1].toString().toLowerCase() == win.g5.et1.text.toLowerCase()) layersFound.push(selectedLayers[s][0]);
}
}
if(layersFound.length == 0) return;
deselectLayers();
for (z in layersFound){
selectLayerById(Number(layersFound[z]), true);
}
}
win.center();
win.show();
}
function getNamesPlusIDs(){
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID('Dcmn'), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
var count = executeActionGet(ref).getInteger(charIDToTypeID('NmbL')) +1;
var Names=[];
try{
activeDocument.backgroundLayer;
var i = 0; }catch(e){ var i = 1; };
for(i;i<count;i++){
if(i == 0) continue;
ref = new ActionReference();
ref.putIndex( charIDToTypeID( 'Lyr ' ), i );
var desc = executeActionGet(ref);
var layerName = desc.getString(charIDToTypeID( 'Nm ' ));
var Id = desc.getInteger(stringIDToTypeID( 'layerID' ));
if(layerName.match(/^<\/Layer group/) ) continue;
var layerType = typeIDToStringID(desc.getEnumerationValue( stringIDToTypeID( 'layerSection' )));
var isLayerSet =( layerType == 'layerSectionContent') ? false:true;
Names.push([[Id],[layerName],[isLayerSet]]);
};
return Names;
};
function deselectLayers() {
var desc01 = new ActionDescriptor();
var ref01 = new ActionReference();
ref01.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
desc01.putReference( charIDToTypeID('null'), ref01 );
executeAction( stringIDToTypeID('selectNoLayers'), desc01, DialogModes.NO );
};
function selectLayerById(ID, add) {
add = (add == undefined) ? add = false : add;
var ref = new ActionReference();
ref.putIdentifier(charIDToTypeID('Lyr '), ID);
var desc = new ActionDescriptor();
desc.putReference(charIDToTypeID('null'), ref);
if (add) {
desc.putEnumerated(stringIDToTypeID('selectionModifier'), stringIDToTypeID('selectionModifierType'), stringIDToTypeID('addToSelection'));
}
desc.putBoolean(charIDToTypeID('MkVs'), false);
executeAction(charIDToTypeID('slct'), desc, DialogModes.NO);
}
Code: Select all#target photoshop
app.bringToFront();
main();
function main(){
if(!documents.length) return;
var selectedLayers = getNamesPlusIDs();
var win = new Window( 'dialog' );
win.p1= win.add("panel", undefined, undefined, {borderStyle:"black"});
win.g1 = win.p1.add('group');
win.g1.orientation = "row";
win.title = win.g1.add('statictext',undefined,'Select Layers by Name');
win.title.alignment="fill";
win.title.graphics.font = ScriptUI.newFont("Georgia","BOLDITALIC",20);
win.g5 =win.p1.add('group');
win.g5.orientation = "column";
win.g5.alignChildren='left';
win.g5.spacing=10;
win.g5.cb1 = win.g5.add('checkbox',undefined,'Case sensitive');
win.g5.cb1.value=true;
win.g5.st1 = win.g5.add('statictext',undefined,'Layer name(s) to select');
win.g5.et1 = win.g5.add('edittext');
win.g5.et1.preferredSize=[250,20];
win.g10 =win.p1.add('group');
win.g10.orientation = "row";
win.g10.alignment='center';
win.g10.spacing=10;
win.g10.bu1 = win.g10.add('button',undefined,'Select Layer(s)');
win.g10.bu1.preferredSize=[110,30];
win.g10.bu2 = win.g10.add('button',undefined,'Cancel');
win.g10.bu2.preferredSize=[110,30];
win.g10.bu1.onClick=function(){
if(win.g5.et1.text == ''){
alert("No layer name has been entered!");
return;
}
win.close(0);
var layersFound = new Array();
for( var s in selectedLayers){
if(win.g5.cb1.value){
if(selectedLayers[s][1].toString() == win.g5.et1.text) layersFound.push(selectedLayers[s][0]);
}else{
if(selectedLayers[s][1].toString().toLowerCase() == win.g5.et1.text.toLowerCase()) layersFound.push(selectedLayers[s][0]);
}
}
if(layersFound.length == 0) return;
deselectLayers();
for (z in layersFound){
selectLayerById(Number(layersFound[z]), true);
}
}
win.center();
win.show();
}
function getNamesPlusIDs(){
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID('Dcmn'), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
var count = executeActionGet(ref).getInteger(charIDToTypeID('NmbL')) +1;
var Names=[];
try{
activeDocument.backgroundLayer;
var i = 0; }catch(e){ var i = 1; };
for(i;i<count;i++){
if(i == 0) continue;
ref = new ActionReference();
ref.putIndex( charIDToTypeID( 'Lyr ' ), i );
var desc = executeActionGet(ref);
var layerName = desc.getString(charIDToTypeID( 'Nm ' ));
var Id = desc.getInteger(stringIDToTypeID( 'layerID' ));
if(layerName.match(/^<\/Layer group/) ) continue;
var layerType = typeIDToStringID(desc.getEnumerationValue( stringIDToTypeID( 'layerSection' )));
var isLayerSet =( layerType == 'layerSectionContent') ? false:true;
Names.push([[Id],[layerName],[isLayerSet]]);
};
return Names;
};
function deselectLayers() {
var desc01 = new ActionDescriptor();
var ref01 = new ActionReference();
ref01.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
desc01.putReference( charIDToTypeID('null'), ref01 );
executeAction( stringIDToTypeID('selectNoLayers'), desc01, DialogModes.NO );
};
function selectLayerById(ID, add) {
add = (add == undefined) ? add = false : add;
var ref = new ActionReference();
ref.putIdentifier(charIDToTypeID('Lyr '), ID);
var desc = new ActionDescriptor();
desc.putReference(charIDToTypeID('null'), ref);
if (add) {
desc.putEnumerated(stringIDToTypeID('selectionModifier'), stringIDToTypeID('selectionModifierType'), stringIDToTypeID('addToSelection'));
}
desc.putBoolean(charIDToTypeID('MkVs'), false);
executeAction(charIDToTypeID('slct'), desc, DialogModes.NO);
}
-
norm
Select multiple layers
Thanks but this isnt what Im looking for.
This is what I have
Code: Select allfunction reColorLinks(name) {
var name = 'Links';
if (name) {
var match = findLayer(activeDocument, name);
if (activeDocument.activeLayer.name == "Links") {
}
}
}
function findLayer(ref, name) {
var layers = ref.layers;
var len = layers.length;
for (var i = 0; i < len; i++) {
var layer = layers;
if (layer.name.toLowerCase() == name.toLowerCase()) {
activeDocument.activeLayer = layer;
}
}
}
This works great but it only selects one layer, is there a way to select 2 layers with the same name on the same level?
This is what I have
Code: Select allfunction reColorLinks(name) {
var name = 'Links';
if (name) {
var match = findLayer(activeDocument, name);
if (activeDocument.activeLayer.name == "Links") {
}
}
}
function findLayer(ref, name) {
var layers = ref.layers;
var len = layers.length;
for (var i = 0; i < len; i++) {
var layer = layers;
if (layer.name.toLowerCase() == name.toLowerCase()) {
activeDocument.activeLayer = layer;
}
}
}
This works great but it only selects one layer, is there a way to select 2 layers with the same name on the same level?
-
norm
Select multiple layers
Does any one know if its even possible to select more than ne layer using a script?
I know you can only have one active layer.
I know you can only have one active layer.
-
Mike Hale
Select multiple layers
You can't select multiple layer with the Photoshop Object Model. You need to use scriptlistener for that. Because you have multiple layers with the same name you will also need to select those layers using the Action Manager layer index which is not the same as Object Model layer index. Finally there isn't a good way with Action Manger to tell how the layers are grouped in layerSets.
It would be too hard to select all the layers in a document with the same name using Action Manager but I am not sure how to go about selecting by name and layerSet level.
It would be too hard to select all the layers in a document with the same name using Action Manager but I am not sure how to go about selecting by name and layerSet level.
-
norm
Select multiple layers
What about selecting all the layers with the same name from a layerset. Would limiting the search down to a layerset make it any easier?
-
Paul MR
Select multiple layers
To select all layers with the same name the code I posted above will/does that.
To select layers with the same name within a layerset is more difficult. first off you need to know how you are selecting the layerset to check.
Once you have the layerset you would then iterate through the layers checking the name and getting the Index or LayerId of matching names. Then select the layers by using the Index or LayerId via AM code.
To select layers with the same name within a layerset is more difficult. first off you need to know how you are selecting the layerset to check.
Once you have the layerset you would then iterate through the layers checking the name and getting the Index or LayerId of matching names. Then select the layers by using the Index or LayerId via AM code.