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

Batch replace a colour with another colour

$
0
0

I have over 100 documents. In these documents, some of the objects use a regular black colour (e.g. C0, M0, Y0, K100). I need to replace it as a rich black (e.g. C75, M68, Y67, K90). The regular black colour is NOT saved as a swatch, so I can't just update the swatch. The objects are made of paths and shapes, some of which are in groups.

 

I found a script here and have updated it to suit my needs (The original script requires you to select an object, my update automatically selects all objects in the file). It works fine on a simple document that has a few layers. However, on more complex documents that have multiple nested layers, I get the following error:

 

Error 1302: No such element

Line: 9

->       myItem=docRef.pathItems[i];

 

 

Here is my code:

var docRef = app.activeDocument;

docRef.hasSelectedArtwork = true;

var iL=docRef.pageItems.length;

 

for (i=0;i<iL;i++){

     myItem=docRef.pathItems[i];

         

          if (myItem.fillColor=="[CMYKColor]" && myItem.selected){ //implement only for CMYK and selected

     var c1=0;

     var m1=0;

     var y1=0;

     var k1=100;

     var c2=Math.round(myItem.fillColor.cyan); // round the number ( 0,0012 => 0 )

     var m2=Math.round(myItem.fillColor.magenta); // round the number ( 6,8898 => 7 )

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

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

     if (c1==c2&&m1==m2&&y1==y2&&k1==k2){ // compare

     myItem.fillColor.cyan=75;

     myItem.fillColor.magenta=68;

     myItem.fillColor.yellow=67;

     myItem.fillColor.black=90;

      redraw();

                    } // if compare

                             

          } // if CMYK

     } // end for

 

How can I overcome the error.


Viewing all articles
Browse latest Browse all 12845

Trending Articles



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