Copy link to clipboard
Copied
Hello everyone,
I was wondering if there was a way to merge swatches via script. I only see ways to add or delete.
Thanks!
Re: Batch replace color with another color
...#target illustrator
var docRef = app.activeDocument;
with (docRef) {
var replaceColor = swatches.getByName('PANTONE 101 C').color;
for (var i = 0; i < pathItems.length; i++) {
with (pathItems) {
if (filled == true && fillColor instanceof SpotColor) {
if (fillColor.spot.name == 'PANTONE 133 C') fillColor = replaceColor;
}
if (stroked == true && strokeColor instanceof SpotColor) {
if (strokeCol
Copy link to clipboard
Copied
Hello man,
I don't understand what kind of merge you want to do, sum your values in new swatche? For example swatche x: cyan = 50 | magenta = 30 | yellow = 0 | black = 10, swatche y: cyan = 10 | magenta = 10 | yellow = 10 | black = 10, swatch result = cyan = 60 | magenta = 40 | yellow = 10 | black = 20.
what purpose of this?
Best regards
VinÃcius
Copy link to clipboard
Copied
I assume he means like this, but with a script.
Copy link to clipboard
Copied
yea exactly, thanks
Copy link to clipboard
Copied
Re: Batch replace color with another color
#target illustrator
var docRef = app.activeDocument;
with (docRef) {
var replaceColor = swatches.getByName('PANTONE 101 C').color;
for (var i = 0; i < pathItems.length; i++) {
with (pathItems) {
if (filled == true && fillColor instanceof SpotColor) {
if (fillColor.spot.name == 'PANTONE 133 C') fillColor = replaceColor;
}
if (stroked == true && strokeColor instanceof SpotColor) {
if (strokeColor.spot.name == 'PANTONE 133 C') strokeColor = replaceColor;
}
}
}
for (var j = 0; j < stories.length; j++) {
with (stories
) { for (var k = 0; k < characters.length; k++) {
with (characters
.characterAttributes) { if (fillColor instanceof SpotColor) {
if (fillColor.spot.name == 'PANTONE 133 C') fillColor = replaceColor;
}
if (strokeColor instanceof SpotColor) {
if (strokeColor.spot.name == 'PANTONE 133 C') strokeColor = replaceColor;
}
}
}
}
}
}
Copy link to clipboard
Copied
var docRef = app.activeDocument;
var colorToKill = 'ORANGE PMS 172';
var colorToLive = 'YELLOW PMS 109';
docRef.selection = null;
var rect = docRef.pathItems.rectangle (20, 0, 20, 20);
rect.filled = true;
rect.fillColor = docRef.swatches.getByName (colorToKill).color;
rect.selected = true;
rect.remove();
app.executeMenuCommand ('Find Fill Color menu item');
for (i = 0; i < docRef.selection.length; i++) {
{
docRef.selection.fillColor = docRef.swatches.getByName (colorToLive).color;
}
}
docRef.selection = null;
var rect = docRef.pathItems.rectangle (20, 0, 20, 20);
rect.stroked = true;
rect.strokeColor = docRef.swatches.getByName (colorToKill).color;
rect.selected = true;
rect.remove();
app.executeMenuCommand ('Find Stroke Color menu item');
for (i = 0; i < docRef.selection.length; i++) {
{
docRef.selection.strokeColor = docRef.swatches.getByName (colorToLive).color;
}
}
docRef.selection = null;
with (docRef) {
for (var j = 0; j < stories.length; j++) {
with (stories
) { for (var k = 0; k < characters.length; k++) {
with (characters
.characterAttributes) { if (fillColor instanceof SpotColor) {
if (fillColor.spot.name == colorToKill) fillColor = swatches.getByName(colorToLive).color;
}
if (strokeColor instanceof SpotColor) {
if (strokeColor.spot.name == colorToKill) strokeColor = swatches.getByName(colorToLive).color;
}
}
}
}
}
}
docRef.swatches.getByName(colorToKill).remove();
Thanks for the help, I learned some new syntax and shortcuts by looking at what you wrote. I will test this out and see if I run into any problems, I would like to avoid looping pathitems if at all possible (I have to deal with a bunch of crazy livetraced crap haha)
Thanks everyone!
Copy link to clipboard
Copied
Credit for writing goes to Muppet Mark‌. I only get credit for needing the info once and passing it on to you. Good Luck.
Copy link to clipboard
Copied
when you select two swatches, and go to merge swatches, the 2nd swatch you select disappears, and everything in the document that had the 2nd swatch takes the color of the 1st swatch you selected.
Copy link to clipboard
Copied
Like in your swatch dialog box, when you select two swatches, and go to merge swatches, the 2nd swatch you select disappears, and everything in the document that had the 2nd swatch takes the color of the 1st swatch you selected.
I understand that I could loop through all the path items in the document, change the fill or/and stroke of the path items with the 2nd swatch to the 1st swatch, and then delete the 2nd swatch, but I was wondering if there was a more efficient way sometime I get documents with thousands and thousands of path items and it takes a minute or two.
I guess another way would be to deselect everything, create a rectangle that's selected with the fill of the 2nd swatch, delete the rectangle, select same fill through menu command, then loop through the selected items and give them all the fill of the 1st swatch....repeat the steps for the stroke....and then delete that 2nd swatch. That would be more efficient than looking for all the paths I will probably go with this plan if there isn't a way to merge swatches.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now