6 Replies Latest reply on Apr 13, 2016 8:04 AM by CarlosCanto

    How do I Change Swatch Names in Illustrator CC 2015?

    paragontony

      First, I know nothing about scripting or writing code.  That being stated, I am trying to use a script to change the swatch names in a PDF file in Illustrator CC 2015 for the PC.  Below is what I have cobbled together.  When the script hits the doc.swatches line I receive a "i is undefined."  I also changed the name of the swatches for the privacy purposes.  Thank you.

       

      var docs = File.openDialog("Select Files to Open", "*.pdf", true);

       

      var idx = 0;

       

      for (idx = 0; idx < docs.length; ++idx) {

       

          var doc = app.open(docs[idx]);

       

          var myCounter = 0;

       

          for (myCounter = 0; myCounter < doc.layers.length; myCounter++) {

       

              doc.layers[myCounter].locked = false;

       

          }

       

              doc.swatches[i].name = doc.swatches[i].name.split('SwatchA').join('AlphaSwatch'); 

            

              doc.swatches[i].name = doc.swatches[i].name.split('SwatchB').join('BetaSwatch');

       

       

      }

        • 1. Re: How do I Change Swatch Names in Illustrator CC 2015?
          Silly-V Adobe Community Professional

          To make this code work, you must understand how the javascript variables and loops work.

          Use this example to get a sense of what the "i" is and why it is not working properly in your snippet.

          http://www.w3schools.com/js/tryit.asp?filename=tryjs_loop_for

          • 2. Re: How do I Change Swatch Names in Illustrator CC 2015?
            paragontony Level 1

            I was able to get further with the script, but it's only changing one of the swatches.  Thoughts?  Thanks in advance.

             

             

             

            var docs = File.openDialog("Select Files to Open", "*.pdf", true);

             

            var idx = 0;

             

            for (idx = 0; idx < docs.length; ++idx)

             

                var doc = app.open(docs[idx]);

             

                var myCounter = 0;

             

                for (myCounter = 0; myCounter < doc.layers.length; myCounter++) {

             

                    doc.layers[myCounter].locked = false;

                   

             

               

                    doc.swatches[idx].name = doc.swatches[idx].name.split('swatch a').join('alpha swatch');

                   

                   

                    doc.swatches[idx].name = doc.swatches[idx].name.split('swatch b').join('beta swatch');

                   

             

                } 

            • 3. Re: How do I Change Swatch Names in Illustrator CC 2015?
              paragontony Level 1

              Ok, I was able to get this script to run correctly, but it only changes one of the swatch names.  What am I missing?  Again, I changed the swatch names for privacy.

               

              var docs = File.openDialog("Select Files to Open", "*.pdf", true);

               

              var i = 0;

               

              for (i = 0; i < docs.length; ++i)

               

                  var doc = app.open(docs[i]);

               

                  var myCounter = 0;

               

                  for (myCounter = 0; myCounter < doc.swatches.length; myCounter++) {

               

                      doc.swatches[myCounter].locked = false;

                     

               

               

                      doc.swatches[i].name = doc.swatches[i].name.split('Swatch A').join('Swatch Alpha');  //this name changes

                  

                      doc.swatches[i].name = doc.swatches[i].name.split('Swatch B').join('Swatch Beta');   //this name doesn't

                     

               

                  } 

              • 4. Re: How do I Change Swatch Names in Illustrator CC 2015?
                CarlosCanto Adobe Community Professional & MVP

                try changing this

                doc.swatches[i].name = doc.swatches[i].name.split('Swatch A').join('Swatch Alpha');


                to this

                doc.swatches[myCounter].name = doc.swatches[myCounter].name.split('Swatch A').join('Swatch Alpha');

                • 5. Re: How do I Change Swatch Names in Illustrator CC 2015?
                  paragontony Level 1

                  Thank you for your quick response and your patience.  When I made the changes I encountered a "MyCounter is undefined" when the script reaches the changed line.

                  • 6. Re: How do I Change Swatch Names in Illustrator CC 2015?
                    CarlosCanto Adobe Community Professional & MVP

                    try this, the mechanics should work,

                     

                     

                     

                    var doc = app.activeDocument;

                     

                     

                    for (var i = 0; i < documents.length; i++) {

                     

                        //var doc = app.open(docs[i]);

                     

                        //var myCounter = 0;

                     

                        for (var myCounter = 0; myCounter < doc.swatches.length; myCounter++) {

                     

                            doc.swatches[myCounter].locked = false;

                          

                     

                     

                            doc.swatches[myCounter].name = doc.swatches[myCounter].name.split('Swatch A').join('Swatch Alpha');  //this name changes

                       

                            //doc.swatches[i].name = doc.swatches[i].name.split('Swatch B').join('Swatch Beta');   //this name doesn't

                          

                     

                        }

                    }