Skip navigation
Clevadio
Currently Being Moderated

Multi-Layer Action

Mar 30, 2011 9:07 AM

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?

 
Replies
  • JJMack
    6,050 posts
    Jan 9, 2006
    Currently Being Moderated
    Mar 30, 2011 11:58 AM   in reply to Clevadio

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 30, 2011 12:28 PM   in reply to Clevadio

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

     

    
    #target Photoshop
    app.bringToFront();
    main();
    function main(){
    if(!documents.length) return;
    var selLayers=[];
    selLayers= getSelectedLayersIdx();
    for (var a in selLayers){
        makeActiveByIndex( selLayers[a], false );
        //amend to suit.
        doAction("ActionName","ActionSet");
        }
    }
    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 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 ); 
    };
    
     
    |
    Mark as:
  • JJMack
    6,050 posts
    Jan 9, 2006
    Currently Being Moderated
    Mar 30, 2011 2:44 PM   in reply to Paul Riggott

    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.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points