Skip to main content
Participant
September 27, 2022
Question

Merge color swatch using script

  • September 27, 2022
  • 2 replies
  • 559 views

Hi everyone,

How can I use script to merge color swatches in Illustrator? I want to be able to select 1 color, cmd click and send a 2nd (or more) colors and merge it using script.

 

There was an older post about this but the link no longer works. Thanks!

 

 

This topic has been closed for replies.

2 replies

Charu Rajput
Community Expert
Community Expert
September 27, 2022
Participant
September 28, 2022

Thanks for the links. It seems like these were the ones I've looked at and tried. My understanding is that you have to declare the swatch name (ex. var replaceColor = swatches.getByName('PANTONE 101 C').color; ) so it wont work on swatch that does not have a name? 

 

I'm just trying to click any color from my swatch panel and select a 2nd one and merged them together. So I dont think they would have a name or cmyk to hardcode in. 

 

Maybe I need a script to find the selected color swatch and then have a 2nd code block to merge?

m1b
Community Expert
Community Expert
September 27, 2022

Hi @Ekin21787927xsfk, I couldn't find a built-in way to merge swatches. In the absence of a simple API, a script could conceivably iterate over every page item in the document and swap all instances of color A with color B, and then remove color A. It wouldn't be 100% robust though, because we don't have access via scripting API to all the properties of appearance. For simple 1 fill, 1 stroke appearances it would be fine.

 

Instead, perhaps an Action could achieve this?

- Mark

Participant
September 28, 2022

I was actually looking at the links from the user posted below and it might be a way? But it wouldn't work when I tried it.