/*
This script performs random color fill.
Select art items and colors in swatches panel and run script.
Note: neighbor art items can get the same colors.
*/
var doc = app.activeDocument;
var selItems = doc.selection;
var sw_sel = doc.swatches.getSelected();
if (sw_sel.lenght==0)
exit;
for (var i=0; i<selItems.length; i++)
{
var selItem = selItems[i];
if(selItem.typename == "PathItem" ||
selItem.typename == "CompoundPathItem")
{
var randomColorIdx = getRandom(0, sw_sel.length - 1);
setColor(selItem, sw_sel[randomColorIdx].color);
}
}
function setColor(pItem, color)
{
pItem.filled = true;
if(pItem.typename == "PathItem")
pItem.fillColor = color;
else
pItem.pathItems[0].fillColor = color;
}
function getRandom(min, max)
{
return Math.floor(Math.random() * (max - min + 1)) + min;
}