Hey everyone, I'm trying to write a script that gathers all selected objects and applies user defined CMYK values at random to the objects. It's based of the random color tutorial that Simon did, only the user should be able to set all color values before it applies those values at random. I'm new to javascript, so it might just be that I'm an idiot and this isn't anywhere close to being a working script. Thanks.
//initiate values for user input
function onInit(){
c1 = 10;
c2 = 10;
c3 = 10;
m1 = 10;
m2 = 10;
m3 = 10;
y1 = 10;
y2 = 10;
y3 = 10;
k1 = 10;
k2 = 10;
k3 = 10;
}
//allow user to input color
function onOptions(){
cmyks = Dialog.prompt("cmyk randomizer:",[
{value: c1, description: "Cyan 1"},
{value: c2, description: "Cyan 2"},
{value: c3, description: "Cyan 3"},
{value: m1, description: "Magenta 1"},
{value: m2, description: "Magenta 2"},
{value: m3, description: "Magenta 3"},
{value: y1, description: "Yellow 1"},
{value: y2, description: "Yellow 2"},
{value: y3, description: "Yellow 3"},
{value: k1, description: "Black 1"},
{value: k2, description: "Black 2"},
{value: k3, description: "Black 3"}
]);
if (values != null) {
c1 = cmyks{0};
c2 = cmyks{1};
c3 = cmyks{2};
m1 = cmyks{3};
m2 = cmyks{4};
m3 = cmyks{5};
y1 = cmyks{6};
y2 = cmyks{7};
y3 = cmyks{8};
k1 = cmyks{9};
k2 = cmyks{10};
k3 = cmyks{11};
}
}
//set input values to cmyk colors
var cmyk = new Array();
cmyk[0] = new CMYKColor((c1)/255,(m1)/255,(y1)/255,(k1)/255);
cmyk[1] = new CMYKColor((c2)/255,(m2)/255,(y2)/255,(k2)/255);
cmyk[2] = new CMYKColor((c3)/255,(m3)/255,(y3)/255,(k3)/255);
//randomization for color array selection
var raw_random_number = Math.random();
var random_number = Math.round(raw_random_number * (cmyk.length));
if (random_number == cmyk.length){random_number = 0};
//set color variable
var color = cmyk[random_number];
//apply color
var sel = activeDocument.getSelectedItems();
for (var i = 0; i < sel.length; i++) {
art = sel[i];
if (art instanceof Path) {
if (art.style.fill.color != null) art.style.fill.color = color;
}
}