6 Replies Latest reply on May 23, 2016 10:18 PM by tpk1982

    Replacing color with color value

    tpk1982 Level 4

      Hi,

       

      I am trying to remove a specific color and remove with another one. How i remove those with color value?

       

      var myColor;
      if(myColor ==  app.documents[0].colors.itemByName("PANTONE 287 C") ||  myColor ==  app.documents[0].colors.itemByName("Primary")){
          myColor.remove("C= 98 M= 75 Y= 7 K= 0")
          }
      

       

      Thanks,

      Karthi

        • 1. Re: Replacing color with color value
          tpk1982 Level 4

          Any suggestions please

          • 2. Re: Replacing color with color value
            AriEss Level 1

            Please try to explain more clearly what you're trying to achieve.

            Thanks!

            • 3. Re: Replacing color with color value
              S Hopkins Adobe Community Professional

              I think I understand what you are trying to achieve. If so, you will use remove (replacingWith) as in:

              var docRef = app.documents.item(0);

              var myColor = docRef.colors.itemByName("PANTONE 287 C");

              var replaceColor = docRef.colors.itemByName("C=98 M=75 Y=7 K=0");

              myColor.remove(replaceColor);

              Note: This also works with swatch references

              • 4. Re: Replacing color with color value
                tpk1982 Level 4

                Hi Hopkins,

                 

                Thanks for your understanding. I have 20 different colors to be replaced with other 20 colors.

                 

                if i do some thing like below it works:

                 

                var docRef = app.documents.item(0);

                var myColor = docRef.colors.itemByName("Primary");

                myColor.remove("Black");

                 

                but instead of giving name Black how i give the black values [0,0,0,100]?

                 

                myColor.remove(docRef.colors.itemByName("C=0 M=0 Y=0 K=100"));

                 

                Thanks,

                Karthi

                • 5. Re: Replacing color with color value
                  natrev Level 3

                  Hi Tpk,

                   

                  Try this code...

                   

                  var len=app.documents[0].colors.length;
                    for(i=0;i<len;i++){
                        myColor=app.documents[0].colors[i];
                        if(myColor ==  app.documents[0].colors.itemByName("Primary")){// Primary is a color Name
                            myColor.remove(app.documents[0].colors.itemByName("C=98 M=75 Y=7 K=0"));//Replace Primary color and replace the color C98 M75 Y7 K0
                        } 
                    }
                  
                  1 person found this helpful
                  • 6. Re: Replacing color with color value
                    tpk1982 Level 4

                    Hi natrev/Hopkins,

                     

                    i missed the following things:

                     

                    1) in my original coding i used space before values C=98 not C= 98

                     

                    2) I have to mention the itemByname: remove(docRef.colors.itemByName("C=0 M=0 Y=0 K=100"));

                     

                    Below coding is working fine:

                     

                    var docRef = app.documents.item(0);

                    var myColor = docRef.colors.itemByName("Primary");

                    myColor.remove(docRef.colors.itemByName("C= 0 M= 0 Y= 0 K= 100"));

                     

                     

                    Thank you so much of your help.

                     

                    Much appreciated.

                     

                    Karthi