Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Batch replace a colour with another colour

Participant ,
Jun 24, 2014 Jun 24, 2014

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;

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;

         

          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.

TOPICS
Scripting
1.5K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
LEGEND ,
Jun 24, 2014 Jun 24, 2014

Have you tried working backwards?

(i=iL;i>=0;i--)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 24, 2014 Jun 24, 2014

@Larry G.Schneider Thanks! Unfortunately, this produces the same error message.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 24, 2014 Jun 24, 2014

Sorry, you haven't enough time for giving a feedback (e.g. Duplicate a layer with a new Name)

And you question here is not easy to answer, I haven't enough time for you - only for a quick start guide.

You should loop through all documents.

You should loop through all items (fill color and stroke color) and change the color if this color is your old black. (Why you won't change the color to RGB-black?)

The difficult is:

- items in nested nested grouped … groups

- colors in strokes and fills were added in the appearance palette cannot be found with scripting

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 24, 2014 Jun 24, 2014

pixxxel schubser Please accept my apologies for my rudeness. If you look at my past questions, you'll see that I normally do give feedback and also mark answers as helpful. In fact the only ones that are unmakred are the ones which were unanswered.

What happened with the Duplicate Layer name project was that my computer went for repairs. When it came back, I had moved on to other things and had completely forgot about it! I know that's not really an excuse, but I didn't mean to skip the feedback on purpose. I do actually contribute on other sites and get frustrated by "help vampires" who ask for help but never give any back, so I am ashamed that I have become one. However, I will make an extra effort to return to my past good habits!

The difficult is:

- items in nested nested grouped … groups

I think that's the problem I've got. In the documents where the script does work, the items are nested in groups.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 24, 2014 Jun 24, 2014

Hi @big_smile,

It's ok.

But you are right, I was a little bit frustrated. Because of: no feedback is the "worst" feedback.

And like I said before, your question isn't easy to answer. To check the difficult you can start with this little snippet:

var aDoc = app.activeDocument;

//var pI = aDoc.pageItems;

//var pILen=pI.length;

// please select some items before running this script snippet

var pI = aDoc.selection;

var pILen=pI.length;

var item;

for (i=0;i<=pILen-1;i++) {

    item = pI;

    $.writeln("item "+i+":  "+item.typename);

    $.writeln("clipped =  "+item.clipped);

    if (item.typename == "PathItem") {

        // if GroupItem --> loop through the groupItems.pathItems

        // if CompoundPathItem --> loop through the CompoundPathItems.pathItems

        $.writeln(item.fillColor)

        $.writeln(item.strokeColor)

        $.writeln(item.filled)

        $.writeln(item.fillColor.color)

        }

        if (item.filled == true && item.fillColor.typename == "CMYKColor" ) {

            alert("item "+i+"  fillColor:  "+item.fillColor.typename);

            }

        if (item.stroked == true && item.strokeColor.typename == "CMYKColor" ) {

            alert("item "+i+"  strokeColor:  "+item.strokeColor.typename);

            }

   }

Please select some items before running this script snippet (otherwise it may takes a long time).

And please, check your JavaScript console in ESTK after running this script.

I know, this can't be a correct answer, but perhaps this is a little bit helpful for the beginning.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 27, 2014 Jun 27, 2014
LATEST

@pixxxel schubser. I think this is actually going to more complicated then I hoped. For my current project, it looks like it will probably be quicker to do it manually. However, I am sure I will probably investigate it in the future. Thanks for your help!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines