-1

So I have a swatch book like the attached image. Each page all the CMK values are the same but only the yellow changes. Right now each page the Yellow changes by 10% (0,10,20,30 etc). Is there a script that could take the existing art (or create a new one) that would change the yellow only on each square to a desired amount? or even if i had a 100 page file where it increases by 1% each page.

Thanks in advance!

Example of CMYK Swatch

aside from selecting each object, not sure what else to do.

1 Answer 1

0

You can try to modify this script:

var doc = app.activeDocument;

var mm = 2.83465;

var start_left = 20*mm;
var start_top = 20*mm;
var gap = 0.2*mm;
var size_3x3_boxes = 5*mm;

var start_color = new CMYKColor();
start_color.c = 0;
start_color.m = 0;
start_color.y = 0;
start_color.k = 0;

var color = start_color;

for (var i=0; i<21; i++) {
    draw_11x11_grid(start_top, start_left, size_3x3_boxes, gap, color)
    start_top += 60*mm;
    color.cyan = 0;
    color.magenta = 0;
    try {color.yellow += 5} catch(e) {} // <-- HERE THE YELLOW IS CHANGING
}

function draw_11x11_grid(start_top, start_left, size, gap, color) {
    var top = start_top;
    for (var j=0; j<11; j++) {
        var left = start_left;
        for (var i=0; i<11; i++) {
            draw_3x3_boxes(top, left, size, gap, color);
            try {color.magenta += 10} catch(e) {}
            left += (size+gap*2);
        }
        left = start_left;
        top += (size+gap*2);
        color.magenta = 0;
        try {color.cyan += 10} catch(e) {}
    }
}

function draw_3x3_boxes(y, x, size, gap, color) {
    var w = (size - gap*2)/3;
    var h = (size - gap*2)/3;
    color.black = 0;
    var box = draw_box(y, x, w, h, color);
    add_two_boxes(box, gap);
    color.black = 30;
    var box = draw_box(y + box.height + gap, x, w, h, color);
    add_two_boxes(box, gap);
    color.black = 60;
    var box = draw_box(y + (box.height + gap)*2, x, w, h, color);
    add_two_boxes(box, gap);
}

function add_two_boxes(box, gap) {
    var box1 = box.duplicate();
    box1.left += box.width + gap;
    box1.fillColor.black += 10;
    var box2 = box1.duplicate();
    box2.left += box.width + gap;
    box2.fillColor.black += 10;
}

function draw_box(y, x, w, h, color) {
    var box = doc.pathItems.rectangle(-y, x, w, h);
    box.stroked = false;
    box.filled = true;
    box.fillColor = color;
    return box;
}

It gets you this:

enter image description here

If you want just to change the yellow channel of selected objects it can be done this way:

var sel = app.selection;
for (var i=0; i<sel.length; i++) {
    try { sel[i].fillColor.yellow += 5 } catch(e) {}
}

It increases by 5% the yellow channel of selected objects.


I changed the first code to make it to create 20 tables with 5% steps of yellow color.

4
  • Thank you! that is exactly what I am looking for! Just one thing, When I change it so the yellow changes by 5% it only creates 10 of the main blocks of colour, what would I need to change as well so it creates 20 main blocks of colour?
    – Trevor H
    Commented Jun 10 at 12:26
  • Probably you have to change the condition of the first loop: for (var i=0; i<11; i++) { to for (var i=0; i<21; i++) {. But it's likely be box will get outside pasteboard. It's need to make the size much smaller. Or you can duplicate the first 10 blocks, select them and run the second script (change the += to -=) Commented Jun 11 at 14:54
  • I just changed the first code in my answer. Commented Jun 11 at 15:08
  • Thanks Yuri! exactly what I wanted! Much appreciated!
    – Trevor H
    Commented Jun 12 at 14:55

Not the answer you're looking for? Browse other questions tagged or ask your own question.