7 Replies Latest reply on Dec 28, 2012 12:14 AM by Vamitul

    rename swatchs

    davidDav

      hi all

       

      how do i rename swatches like DONT PRINT to FINISHING in javascript

       

       

      thanks in advance

      david

        • 1. Re: rename swatchs
          rajnikids Level 1

          Hi david,

           

          try this....

           

           

          var myDoc = app.activeDocument;

          var swatches = myDoc.swatches.everyItem().getElements();

          for (i=0; i<myDoc.swatches.length; i++) {

              swatch= swatches[i];

          if (swatch.name == "DONT PRINT") {

              swatch.name = "FINISHING"

              }

          }

           

          thanks

          • 2. Re: rename swatchs
            davidDav Level 1

            its working...

             

            rajnikids wrote:

             

            Hi david,

             

            try this....

             

             

            var myDoc = app.activeDocument;

            var swatches = myDoc.swatches.everyItem().getElements();

            for (i=0; i<myDoc.swatches.length; i++) {

                swatch= swatches[i];

            if (swatch.name == "DONT PRINT") {

                swatch.name = "FINISHING"

                }

            }

             

            thanks

            if can be much smaller script to rename swatches i would appreciate.

             

             

            thanks

            david

            • 3. Re: rename swatchs
              Vamitul Level 4

              how about like this:

              try { // so it won't crash
                        app.activeDocument.swatches.itemByName("DONT PRINT").name = "FINISHING";
              } catch(e) {
                        alert(e.message + "\r(line " + e.line + ")")
              } //if something went wrong alert
              

               

              if you are shure the color exists, you can shorten it even more:

              app.activeDocument.swatches.itemByName("DONT PRINT").name = "FINISHING";

               

              if you find yourself runnging lots of this one-line "scripts" try my "command box" script:

              http://forums.adobe.com/message/4507144#4507144

              1 person found this helpful
              • 4. Re: rename swatchs
                rajnikids Level 1

                thanks vamitul,, i too have learnt how

                 

                but, can i get clear about

                e.message + "\r(line " + e.line + ")"

                - what does it mean?

                - what is e.line specially...

                 

                thanks

                rkids.

                • 5. Re: rename swatchs
                  Vamitul Level 4

                  i assume you know how the try/catch statement works in javascript. if not, here is a nice guide:

                  http://www.javascriptkit.com/javatutors/trycatch.shtml

                   

                  tha variable e contains is a error object trown form the js interpreter in case something goes wrong (for example if there is no swatch named "DONT PRINT", or if you dont have any opened documents etc).

                  the properties of the error object are:

                   

                  .message = contains the error message

                  .msg = same as above, never used it, just found it in jongware's reference

                  .file = (optional) the name of the file in wich the error ocured

                  .line = (again, optional it seems) the line number in witch the error occured

                  • 6. Re: rename swatchs
                    rajnikids Level 1

                    really very helpful .... vamitul...

                    thanks for the guidance.....

                    • 7. Re: rename swatchs
                      Vamitul Level 4

                      It's Peter Kahrel you should thank, as the alert part is taken straight form one of his examples.