Created
August 22, 2011 13:33
-
-
Save moluapple/1162385 to your computer and use it in GitHub Desktop.
[Illustrator] Delete Unused Swatches
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//only for mark. For work, use John Wundes's script please. | |
//http://www.wundes.com/JS4AI/delete_fluff.js | |
function deleteUnusedSwatches (doc) { | |
var items = doc.pageItems, | |
len = items.length, | |
sw = doc.swatches, | |
slen = sw.length, | |
arr = [], | |
str = null, | |
i = 0, | |
j, | |
temp = [], | |
p, | |
path, | |
isFill = (function (){ | |
p = doc.pathItems.rectangle(0,0,100,100); | |
p.fillColor = sw[2].color; | |
doc.selection = [p]; | |
if (sw.getSelected()[0] == sw[2]){ | |
p.remove(); | |
return 1 | |
} else { | |
p.remove(); | |
return 0 | |
} | |
})(); | |
for (; i < len; i ++){ | |
doc.selection = [items[i]]; | |
arr.push(sw.getSelected()[0]); | |
isFill ? (items[i].stroked && temp.push(items[i].strokeColor)) : (items[i].filled && temp.push(items[i].fillColor)); | |
} | |
while (temp.length){ | |
swatch = temp.pop(); | |
path = doc.pathItems.rectangle(0,0,100,100); | |
isFill ? (path.fillColor = swatch) : (path.strokeColor = swatch); | |
doc.selection = [path]; | |
arr.push(sw.getSelected()[0]); | |
path.remove(); | |
} | |
str = arr.toString(); | |
for (j = slen - 1; j > 1; j --){ | |
RegExp(sw[j].name).test(str) || sw[j].remove(); | |
} | |
} | |
deleteUnusedSwatches(app.activeDocument); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function deleteUnusedSwatches (doc) { | |
var items = doc.pageItems, | |
len = items.length, | |
sw = doc.swatches, | |
slen = sw.length, | |
arr = [], | |
str = null, | |
i = 0, | |
j; | |
for (; i < len; i ++){ | |
doc.selection = [items[i]]; | |
arr.push(sw.getSelected()[0]); | |
} | |
str = arr.toString(); | |
for (j = slen - 1; j > 1; j --){ | |
RegExp(sw[j].name).test(str) || sw[j].remove(); | |
} | |
} | |
deleteUnusedSwatches(app.activeDocument); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sorry, this will not work as expected. But I think it still worth some points. :)