Hi @Dodo Bird, one approach is to use indexOf() to search an Array for a particular string. ExtendScript's Array doesn't come with an indexOf method, so we can make a simple one. Then I've put the filter into a function that also has the list of excluded names—it might be better to put that outside the function in, say, the script settings where you can edit them easily.
Hope that makes sense. 🙂
- Mark
/**
* Using indexOf function to filter spot names.
* @discussion https://community.adobe.com/t5/illustrator-discussions/how-to-determine-whether-the-spot-color-and-exclude-the-specified-spot-color/m-p/13770334
*/
(function () {
// example
var doc = app.activeDocument,
wantedSpots = [];
for (var i = 0; i < doc.spots.length; i++) {
if (spotIsWanted(doc.spots[i]))
wantedSpots.push(doc.spots[i]);
}
$.writeln(wantedSpots);
})();
/**
* Filters a Spot, based
* on internal criteria.
* @param {Spot} spot - an Illustrator Spot.
* @returns {Boolean} - the result.
*/
function spotIsWanted(spot) {
var excludeTheseNames = [
'My Unwanted Spot',
'Even Worse Spot',
'Terrible Spot',
'PANTONE 7607 C',
];
return (
spot.typename === 'Spot'
&& spot.colorType !== ColorModel.REGISTRATION
&& spot.colorType !== ColorModel.PROCESS
&& indexOf(spot.name, excludeTheseNames) === -1
);
};
/**
* Returns index of obj in arr,
* or -1 if not found.
* @param {Array<any>} arr - the array to search.
* @param {any} obj - the object to search for.
* @returns {Number} - the index.
*/
function indexOf(obj, arr) {
for (var i = 0; i < arr.length; i++)
if (obj == arr[i])
return i;
return -1;
};
Edit 2023-05-04: changed indexOf to a normal function, not Array.prototype, for clarity.