Tuesday, July 5, 2016

adobe illustrator - Recolor Artwork: single swatch to multiple swatches



I have an Illustrator document with a lot of objects. All the objects are black, same swatch.


I have a swatch group with a few dozen coloured swatches. I wish to apply these swatches to all the many black objects. It doesn’t have to be in any particular order, but each object should be coloured individually—I don’t just want to change black into some other colour, but to dozens of other colours. What I really want to avoid is having to select each object individually and then applying a different swatch to each.


I’ve never quite managed to get my head properly around the Recolor Artwork feature in Illustrator, and I cannot for the life of me get it to do anything like this. The “New” box in the Recolor Artwork dialogue box appears to accept only one colour.


Is there some way to do this using the Recolor Artwork feature? Or using some other feature that I’m not aware of? Bonus points if there’s a way to control the order in which the colours are applied; e.g., specifying an order and then click on each object in turn to apply each swatch being ‘iterated’ through in that order.


(I would prefer to avoid having to script it, but I will if there’s no other way.)



Answer



The script posted/linked to by Danielillo does most of what I was looking for. I used it as the basis for the following script, which asks the user for the name of the swatch group to use, and then iterates through the selected objects and the swatches in the named swatch group, applying the current colour to the current object.


(The objects I had needed to have their stroke, rather than their fill, changed, so I also changed that. To colour the fill instead of the stroke, replace strokeColor with fillColor.)


var selected = app.activeDocument.selection;
var doc = app.activeDocument;

var swatchIndex = 0;

if (selected instanceof Array) {
title = prompt("Please enter the name of the swatch group containing the colours to apply.", "");

if (title) {
swatches = doc.swatchGroups.getByName(title).getAllSwatches();

if (swatches.length != 0) {
for (i = 0, j = selected.length; i < j; i++) {

item = selected[i];
if (swatchIndex >= swatches.length) swatchIndex = 0;

if (item.typename == "CompoundPathItem") {
item = item.pathItems[0];
}

if (item.typename == "PathItem") {
item.strokeColor = swatches[swatchIndex].color;
swatchIndex++;

}
}
}
}
}

(The script does not handle exceptions, so if you type in an incorrect swatch group name, you’ll probably just get errors thrown at you.)


No comments:

Post a Comment

technique - How credible is wikipedia?

I understand that this question relates more to wikipedia than it does writing but... If I was going to use wikipedia for a source for a res...