Highlighted

Select layers through color

Contributor ,
Sep 27, 2017

Copy link to clipboard

Copied

Greetings everyone! How to select all red colored layers with jsx?

Thank you......

Screenshot_1.jpg

#target photoshop;

app.bringToFront();

if(documents.length) main();

function main(){

var Layers = getColourLayers("red");

deselectLayers();

for(var z in Layers){

    selectLayerById(Number(Layers),true);

    }

};

function getColourLayers(Col){

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

        var Colour = typeIDToStringID(desc.getEnumerationValue(stringIDToTypeID('color')));

        if(layerName.match(/^<\/Layer group/) ) continue;

        var layerType = typeIDToStringID(desc.getEnumerationValue( stringIDToTypeID( 'layerSection' )));

        var isLayerSet =( layerType == 'layerSectionContent') ? false:true;

        if(Colour == Col) Names.push(Id);

   };

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){

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

try{

executeAction(charIDToTypeID("slct"), desc, DialogModes.NO );

}catch(e){}

};

TOPICS
Actions and scripting

Views

536

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

Select layers through color

Contributor ,
Sep 27, 2017

Copy link to clipboard

Copied

Greetings everyone! How to select all red colored layers with jsx?

Thank you......

Screenshot_1.jpg

#target photoshop;

app.bringToFront();

if(documents.length) main();

function main(){

var Layers = getColourLayers("red");

deselectLayers();

for(var z in Layers){

    selectLayerById(Number(Layers),true);

    }

};

function getColourLayers(Col){

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

        var Colour = typeIDToStringID(desc.getEnumerationValue(stringIDToTypeID('color')));

        if(layerName.match(/^<\/Layer group/) ) continue;

        var layerType = typeIDToStringID(desc.getEnumerationValue( stringIDToTypeID( 'layerSection' )));

        var isLayerSet =( layerType == 'layerSectionContent') ? false:true;

        if(Colour == Col) Names.push(Id);

   };

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){

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

try{

executeAction(charIDToTypeID("slct"), desc, DialogModes.NO );

}catch(e){}

};

TOPICS
Actions and scripting

Views

537

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
Sep 27, 2017 1
Most Valuable Participant ,
Sep 27, 2017

Copy link to clipboard

Copied

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
Reply
Loading...
Sep 27, 2017 1
Contributor ,
Sep 27, 2017

Copy link to clipboard

Copied

Hi pixxxel schubser I had already tested this script ... it just checks if there is red color layer however, it is not able to select the same.

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
Reply
Loading...
Sep 27, 2017 0
Guide ,
Sep 27, 2017

Copy link to clipboard

Copied

#target photoshop;

app.bringToFront();

if(documents.length) main();

function main(){

var Layers = getColourLayers("red");

deselectLayers();

for(var z in Layers){

    selectLayerById(Number(Layers),true);

    }

};

function getColourLayers(Col){

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

        var Colour = typeIDToStringID(desc.getEnumerationValue(stringIDToTypeID('color')));

        if(layerName.match(/^<\/Layer group/) ) continue;

        var layerType = typeIDToStringID(desc.getEnumerationValue( stringIDToTypeID( 'layerSection' )));

        var isLayerSet =( layerType == 'layerSectionContent') ? false:true;

        if(Colour == Col) Names.push(Id);

   };

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){

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

try{

executeAction(charIDToTypeID("slct"), desc, DialogModes.NO );

}catch(e){}

};

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
Reply
Loading...
Sep 27, 2017 4
Contributor ,
Sep 27, 2017

Copy link to clipboard

Copied

Perfect! Grade 10! Thank you SuperMerlin

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
Reply
Loading...
Sep 27, 2017 0
New Here ,
Sep 28, 2020

Copy link to clipboard

Copied

Hi. I've got this error. Please can someone help?


we123.png

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
Reply
Loading...
Sep 28, 2020 0
Adobe Community Professional ,
Sep 28, 2020

Copy link to clipboard

Copied

Side effects of transferring text from the old scripting forum to this new forum. Part of the text (in square brackets) is lost.

Replace
 
for(var z in Layers){
selectLayerById(Number(Layers),true);
}

with
 
for(var z in Layers){
selectLayerById(Number(Layers[z]),true);
}
 

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
Reply
Loading...
Sep 28, 2020 2
New Here ,
Sep 28, 2020

Copy link to clipboard

Copied

Thanks a lot for quick response. Works like a charm!

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
Reply
Loading...
Sep 28, 2020 0
Enthusiast ,
Sep 27, 2017

Copy link to clipboard

Copied

btw you can use filter by color in layer panel. But only for manual work. This filter can't be scripted.

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
Reply
Loading...
Sep 27, 2017 1