2 Replies Latest reply on Apr 21, 2015 3:59 PM by Jeff S GP2

    Ignore Error

    Jeff S GP2 Level 1

      I have this simple script  ( action converted to java) that renames a layer "Test" to "H_Test' than duplicates with the name "B_Test"

      Is there an additional line of code i can include to ignore this process, if the layer name "Test" does not appear within the layers list?

       

      Many thanks!

       

       

       

       

      #target photoshop

      //

       

      cTID = function(s) { return app.charIDToTypeID(s); };

      sTID = function(s) { return app.stringIDToTypeID(s); };

       

      //

      //==================== Select_byName_AddPrefix_Duplicate ==============

      //

      function Select_byName_AddPrefix_Duplicate() {

        // Select

        function step1(enabled, withDialog) {

          if (enabled != undefined && !enabled)

            return;

          var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);

          var desc1 = new ActionDescriptor();

          var ref1 = new ActionReference();

          ref1.putName(cTID('Lyr '), "Test");

          desc1.putReference(cTID('null'), ref1);

          desc1.putBoolean(cTID('MkVs'), false);

          executeAction(cTID('slct'), desc1, dialogMode);

        };

       

        // Set

        function step2(enabled, withDialog) {

          if (enabled != undefined && !enabled)

            return;

          var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);

          var desc1 = new ActionDescriptor();

          var ref1 = new ActionReference();

          ref1.putEnumerated(cTID('Lyr '), cTID('Ordn'), cTID('Trgt'));

          desc1.putReference(cTID('null'), ref1);

          var desc2 = new ActionDescriptor();

          desc2.putString(cTID('Nm  '), "H_Test");

          desc1.putObject(cTID('T   '), cTID('Lyr '), desc2);

          executeAction(cTID('setd'), desc1, dialogMode);

        };

       

        // Duplicate

        function step3(enabled, withDialog) {

          if (enabled != undefined && !enabled)

            return;

          var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);

          var desc1 = new ActionDescriptor();

          var ref1 = new ActionReference();

          ref1.putEnumerated(cTID('Lyr '), cTID('Ordn'), cTID('Trgt'));

          desc1.putReference(cTID('null'), ref1);

          desc1.putString(cTID('Nm  '), "B_Test");

          desc1.putInteger(cTID('Vrsn'), 2);

          executeAction(cTID('Dplc'), desc1, dialogMode);

        };

       

        step1();      // Select

        step2();      // Set

        step3();      // Duplicate

      };

       

       

       

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

      //                    Select_byName_AddPrefix_Duplicate.main

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

      //

       

      Select_byName_AddPrefix_Duplicate.main = function () {

        Select_byName_AddPrefix_Duplicate();

      };

       

      Select_byName_AddPrefix_Duplicate.main();

       

      // EOF

       

      "Select_byName_AddPrefix_Duplicate.jsx"

      // EOF

        • 1. Re: Ignore Error
          DBarranca Level 4

          Hi,

          easiest one is to wrap step1 in a try/catch block.

           

          #target photoshop
          //
          
          cTID = function(s) { return app.charIDToTypeID(s); };
          sTID = function(s) { return app.stringIDToTypeID(s); };
          
          //
          //==================== Select_byName_AddPrefix_Duplicate ==============
          //
          function Select_byName_AddPrefix_Duplicate() {
            // Select
            function step1(enabled, withDialog) {
              if (enabled != undefined && !enabled)
                return;
              var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
              var desc1 = new ActionDescriptor();
              var ref1 = new ActionReference();
              ref1.putName(cTID('Lyr '), "Test");
              desc1.putReference(cTID('null'), ref1);
              desc1.putBoolean(cTID('MkVs'), false);
              executeAction(cTID('slct'), desc1, dialogMode);
            };
          
            // Set
            function step2(enabled, withDialog) {
              if (enabled != undefined && !enabled)
                return;
              var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
              var desc1 = new ActionDescriptor();
              var ref1 = new ActionReference();
              ref1.putEnumerated(cTID('Lyr '), cTID('Ordn'), cTID('Trgt'));
              desc1.putReference(cTID('null'), ref1);
              var desc2 = new ActionDescriptor();
              desc2.putString(cTID('Nm  '), "H_Test");
              desc1.putObject(cTID('T   '), cTID('Lyr '), desc2);
              executeAction(cTID('setd'), desc1, dialogMode);
            };
          
            // Duplicate
            function step3(enabled, withDialog) {
              if (enabled != undefined && !enabled)
                return;
              var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
              var desc1 = new ActionDescriptor();
              var ref1 = new ActionReference();
              ref1.putEnumerated(cTID('Lyr '), cTID('Ordn'), cTID('Trgt'));
              desc1.putReference(cTID('null'), ref1);
              desc1.putString(cTID('Nm  '), "B_Test");
              desc1.putInteger(cTID('Vrsn'), 2);
              executeAction(cTID('Dplc'), desc1, dialogMode);
            };
          
            try {
              step1();      // Select
            } catch(e) {
              return;
            }
            step2();      // Set
            step3();      // Duplicate
          };
          
          
          
          //=========================================
          //                    Select_byName_AddPrefix_Duplicate.main
          //=========================================
          //
          
          Select_byName_AddPrefix_Duplicate.main = function () {
            Select_byName_AddPrefix_Duplicate();
          };
          
          Select_byName_AddPrefix_Duplicate.main();
          
          // EOF
          
          "Select_byName_AddPrefix_Duplicate.jsx"
          // EOF
          

           

          Regards

           

          Davide Barranca

          ---

          www.davidebarranca.com

          www.cs-extensions.com

          • 2. Re: Ignore Error
            Jeff S GP2 Level 1

            Thank you very much!

             

            Cheers!