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

Delete Swatches

Participant ,
Mar 13, 2018 Mar 13, 2018

Why does this half work??  removeAll works but I need to delete specifics through a loop.

var myColor = app.activeDocument.swatches;

    for( i=0; i<myColor.length; i++ ){     

        var currentItem = myColor;

        currentItem.remove();

}

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

Community Expert , Mar 13, 2018 Mar 13, 2018

I rewrote your code. However, not tested.

var myColor = app.activeDocument.swatches;

var len = myColor.length - 1;

for( i=len; i>0; i-- ){    

   myColor.remove();

}

swatches collection update each time in for roop.

When i variable reaches half, swatch collections length number is also reduced by half, so they become equal.

Translate
Adobe
Community Expert ,
Mar 13, 2018 Mar 13, 2018

I rewrote your code. However, not tested.

var myColor = app.activeDocument.swatches;

var len = myColor.length - 1;

for( i=len; i>0; i-- ){    

   myColor.remove();

}

swatches collection update each time in for roop.

When i variable reaches half, swatch collections length number is also reduced by half, so they become equal.

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 ,
Mar 14, 2018 Mar 14, 2018

This is correct and does work (tested) but when I write the exception for a specific swatch ES gives me "can't find name".  Although I get the name with an alert?

var myColor = app.activeDocument.swatches; 

var len = myColor.length - 1;

for( i=len; i>0; i-- ){

    if (myColor.name = "My Swatch" ){

        }

    else {

    myColor.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 ,
Mar 14, 2018 Mar 14, 2018

Here is a correct syntax.

if (myColor.name == "My Swatch") {

You can reference comparison operator in  JavaScript Operators .

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 ,
Mar 14, 2018 Mar 14, 2018
LATEST

Thanks for pointing out I was missing part of my operator = ha. Works!!

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