2 Replies Latest reply on Dec 17, 2012 10:23 AM by Jeff S GP2

    If, Then, based on layer name

    Jeff S GP2 Level 1

      Is it possible to create a script that calls an action based on a layers name?

       

      I have hundreds of image documents (layered psd's) that need specific images inserted at different scales.

      I can make these individual actions, but would need help with the beginning  "if then part"

       

      As an example:

       

      if a layer is called RN 100  it will call one action

      if another layer is called RN 205 it will call another action.

      if there is no recognizable layer name, it simply closes that document

       

      Thanks for any help

       

      Jeff

        • 1. Re: If, Then, based on layer name
          Ghoulfool Level 1

          This is the basis of what you want:

          It ignore the background, you need to change the script to call the actions you need. At the moment it calls "ACTION1" & "ACTION1". The script doesn't take into account groups of if  one of your layers is a variane to what you asked for ie "Rn 100" or "rn 100"

           

          var srcDoc = app.activeDocument;

          var numOfLayers = srcDoc.layers.length;

           

          // main loop starts here

          for (var i = numOfLayers -2; i >= 0  ; i--) //igore background

          {

           

              srcDoc.activeLayer = srcDoc.artLayers[i];

              var temp = srcDoc.artLayers[i].name

              if (temp == "RN 100")

              {

                  // =======================================================

                  var id156 = charIDToTypeID( "Ply " );

                  var desc39 = new ActionDescriptor();

                  var id157 = charIDToTypeID( "null" );

                  var ref20 = new ActionReference();

                  var id158 = charIDToTypeID( "Actn" );

                  ref20.putName( id158, "ACTION1" ); // action 1 name

                  var id159 = charIDToTypeID( "ASet" );

                  ref20.putName( id159, "Scripts" );

                  desc39.putReference( id157, ref20 );

                  executeAction( id156, desc39, DialogModes.NO );

              }

              else if (temp == "RN 205")

              {

                  // =======================================================

                  var id156 = charIDToTypeID( "Ply " );

                  var desc39 = new ActionDescriptor();

                  var id157 = charIDToTypeID( "null" );

                  var ref20 = new ActionReference();

                  var id158 = charIDToTypeID( "Actn" );

                  ref20.putName( id158, "ACTION2" ); //action 2 name

                  var id159 = charIDToTypeID( "ASet" );

                  ref20.putName( id159, "Scripts" );

                  desc39.putReference( id157, ref20 );

                  executeAction( id156, desc39, DialogModes.NO );

              }

              else

              {

                  //close without saving

                 app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);

              }

          }//end loop

           

          Hope this helps

          • 2. Re: If, Then, based on layer name
            Jeff S GP2 Level 1

            Wow!.. fantastic

             

            I can see allot of potential for this kind of script.

             

            Thanks allot,  I really appreciate this!

             

            Jeff