3 Replies Latest reply on Mar 30, 2011 2:44 PM by JJMack

    Multi-Layer Action


      I want to create a script that can acknowledge several layers that I have selected, random in name and contents, and then run one action on each of those layers. Is that possible to do?

        • 1. Re: Multi-Layer Action
          JJMack Most Valuable Participant

          A script can run actions and it could target a layer before doing the action. However an action can add and delete and rename layers. When the running script get back in control when the action has finished doing its thing. The originaly selected layer existance, names and positions in the layers stack may have changed. You may need verify the layers becareful know what the actions do and how they work. giving control to the user or an process that you do not know what it may do may do somthing the could potenionaly break the process that called it.

          • 2. Re: Multi-Layer Action
            Paul Riggott Level 6

            This will run an action on the selected layers...


            #target Photoshop
            function main(){
            if(!documents.length) return;
            var selLayers=[];
            selLayers= getSelectedLayersIdx();
            for (var a in selLayers){
                makeActiveByIndex( selLayers[a], false );
                //amend to suit.
            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++){ 
                           selectedLayers.push(  desc.getReference( i ).getIndex() ); 
                           selectedLayers.push(  desc.getReference( i ).getIndex()+1 ); 
                     var ref = new ActionReference(); 
                     ref.putProperty( charIDToTypeID("Prpr") , charIDToTypeID( "ItmI" )); 
                     ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
                        selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" ))-1); 
                        selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" ))); 
                  return selectedLayers; 
            function makeActiveByIndex( idx, visible ){ 
                var desc = new ActionDescriptor(); 
                  var ref = new ActionReference(); 
                  ref.putIndex(charIDToTypeID( "Lyr " ), idx) 
                  desc.putReference( charIDToTypeID( "null" ), ref ); 
                  desc.putBoolean( charIDToTypeID( "MkVs" ), visible ); 
               executeAction( charIDToTypeID( "slct" ), desc, DialogModes.NO ); 
            • 3. Re: Multi-Layer Action
              JJMack Most Valuable Participant

              Paul's script works very well just remember not to run any actions that may delete a layers particulary right above the bottom layer this seem to change layers index number and after the action runs the first time the active layer on the following run of the action will not be the other layers you had selected.

              1 person found this helpful