3 Replies Latest reply on Oct 13, 2009 3:17 PM by Danny Noonan

    [JS [CS4] Find color by value and replace

    Danny Noonan Level 1

      I am having trouble grasping the concept of colors and swatches. I have searched this forum inside out and can't seem to find what I am looking for. I would like to have a script which will find any color with values 0,0,0,100 and replace it/them with system [Black]. We are having problems with customers making they're own black(s). When they make a black swatch, the black will not overprint like system Black.

      All I have so far is a portion of script that will add a "false" black. I want to do this in case a document doesn't have any, it will merge this one without the javascript erroring out(is this the right way to go about it?). I need to figure out how to find all of these false blacks and replace/merge with system black.

       

      var myDoc = app.activeDocument;

      var myColor = myDoc.colors.add();

      myColor.colorValue = [0,0,0,100];

       

       

      Thanks for any help in advance . . .

       

      Danny

        • 1. Re: [JS [CS4] Find color by value and replace
          Danny Noonan Level 1

          Why doesn't this work? Am I not referencing the system Black correctly?

          Any help would be greatly appreciated.

           

          Thanks,

           

          Danny

           

           

           

          var myColor = myDoc.colors.add();

          myColor.colorValue = [0,0,0,100];

           

          function replaceSwatch(doc, BadSwatch, GoodSwatch) {

          var BadSwatch = doc.swatches.item([0,0,0,100]);

          var GoodSwatch = doc.swatches.item([Black]);

          BadSwatch.remove([Black]);

          }

           

          • 2. Re: [JS [CS4] Find color by value and replace
            [Jongware] Most Valuable Participant

            Hmm. I never script with colors, but there have been reports that Javascript cannot work reliably with a 'color' object. If you first do an "add all colors as swatches" (somewhere in the Swatch panel menu), you get names for your colors. Then use the swatch name to find the color. It might be that

             

            var BadSwatch = doc.swatches.item([0,0,0,100]);

             

            always returns the built-in black ...

             

            You also need quotes around item names!

             

            doc.swatches.item("[Black]")

             

            (A propos, black is always present as #2: doc.swatches[2] works fine.)

            1 person found this helpful
            • 3. Re: [JS [CS4] Find color by value and replace
              Danny Noonan Level 1

              Thanks for responding Jongware.

               

              The problem I'm having is the 0,0,0,100 swatches are in the Swatches Panel BUT they have inconsistent names from page to page. I thought the best way to hunt these out would be by finding them by their values. Would it be possible to locate these bad swatches excluding the built-in-black.

               

               

              var myDoc = app.activeDocument;

              var myColor = myDoc.colors.add();

              myColor.colorValue = [0,0,0,100];

               

              function replaceSwatch(doc, BadSwatch, GoodSwatch) {

              var BadSwatch = myDoc.swatches.item([0,0,0,100]);

               

                   //Thanks for the tip on the [2], I knew I was missing something. That being said, do I need the quotes here?

               

              var GoodSwatch = myDoc.swatches[2];

              BadSwatch.remove([2]);

              }

               

               

               

              Thanks again Jong, I appreciate your help