Skip to main content
wckdtall
Inspiring
March 10, 2023
Question

Is it possible to move swatches, sort or reorder them?

  • March 10, 2023
  • 1 reply
  • 1036 views

I'm looking to organize my Illustrator files a bit through scripting, and I'd like to be able to reorder swatches. I was hoping it was as simple as setting an index to an integer but it's not possible. The script I have loops through all document swatches and adds them to a Swatch Group, and I'm left with the patterns in the document, in whatever order they started.

 

A few ideas of how to accomplish if it's not as simple as changing the index:

Can I delete and readd the swatch to the panel?

Am I able to sort swatches via scripting? I searched through menu commands and it doesn't look like it's possible, but this would be an easy loop to organize.

This topic has been closed for replies.

1 reply

Sergey Osokin
Inspiring
March 10, 2023

Sorting is possible with a trick:

1) Create an action with the command from the Swatches > Sort by Name panel menu.
2) Add a sequential number to the existing swatch names. For example: red > 2@red, green > 1@green
3) Execute the action. It will sort the swatches according to our indexes.
4) Loop through the swatch names in the document and delete the "Num@" prefix.

wckdtall
wckdtallAuthor
Inspiring
March 10, 2023

Thanks! Good solution. Actions won't work for me, since calling a script with an action through an action causes the script to crash if I recall.

Sergey Osokin
Inspiring
March 10, 2023

Then there's a problem. Either we need to add the swatches in the desired order first, or we need a sort command that can only be accessed via actions =(