Quantcast
Channel: Adobe Community : Popular Discussions - Illustrator Scripting
Viewing all articles
Browse latest Browse all 12845

CMYK to Spot conversion

$
0
0

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--){

                doc.swatches[i].remove();

            }

     

var doc= app.activeDocument;

var L=docRef.pathItems.length;

 

 

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

{

     myItem=doc.pathItems[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.


Viewing all articles
Browse latest Browse all 12845

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>