5 Replies Latest reply on Sep 27, 2017 10:04 PM by Jarda Bereza

    Select layers through color

    tokuredit Level 1

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

      Thank you......

      Screenshot_1.jpg

        • 2. Re: Select layers through color
          tokuredit Level 1

          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.

          • 3. Re: Select layers through color
            SuperMerlin Level 5
            #target photoshop;
            app.bringToFront();
            if(documents.length) main();
            function main(){
            var Layers = getColourLayers("red");
            deselectLayers();
            for(var z in Layers){
                selectLayerById(Number(Layers[z]),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){}
            };
            
            
            
            3 people found this helpful
            • 4. Re: Select layers through color
              tokuredit Level 1

              Perfect! Grade 10! Thank you SuperMerlin

              • 5. Re: Select layers through color
                Jarda Bereza Level 4

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