Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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 =(
Copy link to clipboard
Copied
I thought of deleting and readding the swatches in order, but swatches.remove(); removes the fill from the document. I tried cutting a filled path, deleting the swatch, and pasting the path and it does reorder the swatches in the preferred order, but then of course the document is changed to a state that's not preferred.