5 Replies Latest reply on Feb 11, 2015 12:15 PM by Qwertyfly...

    CMYK to Spot conversion

    Zantcor Level 1

      I created a script that goes through the path objects one a time, converts the cmyk values over to a spot color, then applies that new swatch to path item. It works when it comes to grabbing the object, and creating the swatches but it breaks when I go to grab the swatch and apply it to the object. Any ideas?


      Below the line of * I've copied the script, everything is written in Java.  Any help would be much appreciated.


      ****************************************************************************************** **********************************************************************


      //Created by Daryl Smith 2-4-15


      #target illustrator



      var docRef = app.activeDocument;

      var paths = docRef.pathItems;


      //first we have to remove all the swatches except for the registration (swatch 0) to prevent mistakes later in the script and printing process

      var doc=app.activeDocument;

                  for(var i=doc.swatches.length-1; i>1; i--){




      var doc= app.activeDocument;

      var L=docRef.pathItems.length;



      for (i=0;i<L;i++)




                if (myItem.fillColor=="[CMYKColor]")


                     var c=Math.round(myItem.fillColor.cyan);

                     var m=Math.round(myItem.fillColor.magenta);

                     var y=Math.round(myItem.fillColor.yellow);

                     var k=Math.round(myItem.fillColor.black);

                     alert ("pathItem number: "+(i+1)+" \n cyan: "+c+" \n magenta: "+m+" \n yellow: "+y+" \n black: "+k);


           //sets up the new swatch with the same CMYK values as the first path item but makes it a spot color

           //this will let the printer see only one color instead of four for cmyk


           var replaceColor = docRef.spots.add();

           replaceColorColor = new CMYKColor();

           replaceColorColor.cyan = c;

           replaceColorColor.magenta = m;

           replaceColorColor.yellow = y;

           replaceColorColor.black = k;

           replaceColor.name = "Color" + (i+1);

           replaceColor.color = replaceColorColor;

           replaceColor.colorType = ColorModel.SPOT;

           replaceColor.tint = 100;


           //grab color swatch that matches the path item number

           //the swatch should be the same color as it was just made, but it is now a spot color


              var ncolor = docs.swatches[i].color;


              if (doc.pathItems[i].fillcolor = true){


              doc.pathItems[i].fillColor = ncolor;

              }//end if



          }//end if


        }//end for



      //this is to list the number of colors that the printer will see, along with the list of color names that are in the ink list

      alert("You have " + app.activeDocument.inkList.length + " colors and your active colors are" + app.activeDocument.inkList); // returns: "undefined"


      ****************************************************************************************** ****************************************************************


      I'm not sure how to upload my script like I see so many others doing so if you want to explain I would be more than happy to upload it.


      I figured out what was the issue, it was line 50 "docs.swatches[i].color" I had left off the "docs." so it couldn't find the referenced colors but now when it applies them it is randomly applying them it seems like instead of doing it in the same order.

        • 1. Re: CMYK to Spot conversion
          Zantcor Level 1

          On line 50 I had left off "doc." on the "docs.swatches[i].color" so it couldn't find the referenced swatch but now it is applying it randomly to the path items instead of the same order it was created.


          How do I make it keep the same order?

          • 2. Re: CMYK to Spot conversion
            Zantcor Level 1

            Well after working on this for 8 hours and hitting the wall I posted it on here and I've already figured out 2 of my problems.  I had to increase the increment on line 50 to read "docs.Swatches[i+2].com".   My next big problem that I'm trying to figure out is how to stop it from making a swatch for every item if the swatch already exists for that given CMYK value.  This way if I have a group of artwork that is one color but many objects that it dosn't make 30 swatches for one CMYK color.

            • 3. Re: CMYK to Spot conversion
              Qwertyfly... Level 4

              Would it be nice and simple to Select your art.

              hit add new swatch group in the swatch panel.


              Then Shift Select all the swatches in that group, hit the options button and change the colour type to spot?


              • 4. Re: CMYK to Spot conversion
                Zantcor Level 1

                Thank you for your help, I don't know why I was doing it the complicated way.  Maybe someone can take the bit of script that I had wrote and turn it into something useful.


                Thanks again imagecollection!

                • 5. Re: CMYK to Spot conversion
                  Qwertyfly... Level 4

                  I have done the same thing many times.

                  put hours into a script, or an artwork

                  only to find it was a basic quick task once you know how to tackle it.

                  glad I could help.