[JS][CS5] rounding decimals in swatch values
Hello again,
I recently made this script to round decimals in the swatch values if there were any. I'm pretty new to JS so this probably isn't the prettiest code so I was wondering if someone had a better way of doing it. This works, but sometimes it takes a while and I'm pretty sure it is looking at the [paper], [black], and other swatches that can't be changed. That is why I made it skip the errors during the script...
function round(color) {
try { color.space = ColorSpace.cmyk;
var vals = color.colorValue;
for (var j = vals.length - 1; j >= 0; j--) {
vals
= Math.round(vals ); }
color.colorValue = vals;
} catch (err) {}
}
if (app.documents.length > 0) {
var target = app.documents[0];
} else {
var target = app;
}
var myColors = target.colors.everyItem().getElements();
for (var j = myColors.length - 1; j >= 0; j--) {
round(myColors
); }
alert("Swatches Rounded");
Any help is appreciated.
