Copy link to clipboard
Copied
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();
}
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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();
}
}
Copy link to clipboard
Copied
Here is a correct syntax.
if (myColor.name == "My Swatch") {
You can reference comparison operator in JavaScript Operators .
Copy link to clipboard
Copied
Thanks for pointing out I was missing part of my operator = ha. Works!!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now