• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
1

Select layers through color

Contributor ,
Sep 27, 2017 Sep 27, 2017

Copy link to clipboard

Copied

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

Thank you......

Screenshot_1.jpg

TOPICS
Actions and scripting

Views

1.0K

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

Guide , Sep 27, 2017 Sep 27, 2017

#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

...

Votes

Translate

Translate
Adobe
Community Expert ,
Sep 27, 2017 Sep 27, 2017

Copy link to clipboard

Copied

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

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
Guide ,
Sep 27, 2017 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){}

};

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
Contributor ,
Sep 27, 2017 Sep 27, 2017

Copy link to clipboard

Copied

Perfect! Grade 10! Thank you SuperMerlin

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
New Here ,
Sep 28, 2020 Sep 28, 2020

Copy link to clipboard

Copied

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


we123.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
Valorous Hero ,
Sep 28, 2020 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);
}
 

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
New Here ,
Sep 28, 2020 Sep 28, 2020

Copy link to clipboard

Copied

LATEST

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

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
Enthusiast ,
Sep 27, 2017 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.

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