3 Replies Latest reply on Nov 8, 2011 6:24 PM by Tatsu_

    I want to get the multiple selected layers name.

    Tatsu_ Level 1

      I want to get the multiple selected layers name.

       

      The "activeDocument.activeLayer" command returns only one layer name. Even if multiple layers were selected.

       

      Can I solve the problem?

        • 1. Re: I want to get the multiple selected layers name.
          Paul Riggott Level 6

          Please try this example...

           

           

          #target Photoshop
          app.bringToFront();
          main();
          function main(){
          if(!documents.length) return;
          var selectedLayers = getSelectedLayersIdx();
          var selectedLayersNames =[];
          for(var a in selectedLayers){
              selectedLayersNames.push(getLayerNameByIndex( Number(selectedLayers[a]) ));
              }
          alert("Number of Layers selected = " + selectedLayers.length + "\rLayer Names = " + selectedLayersNames.toString());
          }
          
          function getLayerNameByIndex( idx ) { 
              var ref = new ActionReference(); 
              ref.putProperty( charIDToTypeID("Prpr") , charIDToTypeID( "Nm  " )); 
              ref.putIndex( charIDToTypeID( "Lyr " ), idx );
              return executeActionGet(ref).getString(charIDToTypeID( "Nm  " ));; 
          };
          function getSelectedLayersIdx(){ 
                var selectedLayers = new Array; 
                var ref = new ActionReference(); 
                ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
                var desc = executeActionGet(ref); 
                if( desc.hasKey( stringIDToTypeID( 'targetLayers' ) ) ){ 
                   desc = desc.getList( stringIDToTypeID( 'targetLayers' )); 
                    var c = desc.count 
                    var selectedLayers = new Array(); 
                    for(var i=0;i<c;i++){ 
                      try{ 
                         activeDocument.backgroundLayer; 
                         selectedLayers.push(  desc.getReference( i ).getIndex() ); 
                      }catch(e){ 
                         selectedLayers.push(  desc.getReference( i ).getIndex()+1 ); 
                      } 
                    } 
                 }else{ 
                   var ref = new ActionReference(); 
                   ref.putProperty( charIDToTypeID("Prpr") , charIDToTypeID( "ItmI" )); 
                   ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
                   try{ 
                      activeDocument.backgroundLayer; 
                      selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" ))-1); 
                   }catch(e){ 
                      selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" ))); 
                   } 
                } 
                return selectedLayers; 
          };
          function selectLayerByIndex(index,add){ 
           add = (add == undefined)  ? add = false : add;
           var ref = new ActionReference();
              ref.putIndex(charIDToTypeID("Lyr "), index);
              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){}
          };
          
          
          • 2. Re: I want to get the multiple selected layers name.
            Michael L Hale Level 5

            What version of Photoshop are you using? With newer versions you can determine multiple selected layers using Action Manger.

             

            EDIT: Paul beat me to this with the AM code. But it will not work with older version of Photoshop because they don't have the needed document descriptor key.

            • 3. Re: I want to get the multiple selected layers name.
              Tatsu_ Level 1

              >Paul

              I got the layers name.

              You have helped me greatly.

              I appreciate your assistance indeed.

               

               

              >Michael

              I use CS3.The Paul's script running well !