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

Remove swatches not working

Community Beginner ,
Sep 17, 2014 Sep 17, 2014

I am using Javascript to script Illustrator. I have a simple for loop which goes over each swatch in the document and removes it... or so I thought. For some reason, only around half of the swatches are actually removed. No error is thrown so I have no idea why it is not working.

Code:

  for(var i = 0; i < activeDocument.swatches.length; i++) {

    activeDocument.swatches.remove();

  }

Also note that this works for a few swatches but when you add any significant amount (I have 16), it only removes about half of them.

TOPICS
Scripting
455
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

correct answers 1 Correct answer

Valorous Hero , Sep 17, 2014 Sep 17, 2014

Maybe try in reverse?

Also be aware you do not want to remove the registration and the no-color swatch.

        var doc=app.activeDocument;

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

            doc.swatches.remove();

        }

Translate
Adobe
Valorous Hero ,
Sep 17, 2014 Sep 17, 2014

Maybe try in reverse?

Also be aware you do not want to remove the registration and the no-color swatch.

        var doc=app.activeDocument;

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

            doc.swatches.remove();

        }

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 ,
Sep 17, 2014 Sep 17, 2014
LATEST

As V points out when working with anything with an index, you need to remove things in reverse so as not to change the index.

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