Copy link to clipboard
Copied
Hi all,
I'm really hoping someone can help me out. I need a script that sorts layers (with sublayers) in Illustrator as they appear on the artboard (top to bottom).
I have a selection of colour swatches that I need to keep in the correct order, as you can see in the layers panel they don't match how my current artwork looks.
I understand I could manually arrange these within the layers panel, however sometimes I'll be working with over 500 swatches.
Any help would greatly be appreciated.
Thanks, Sammy
Copy link to clipboard
Copied
Are you looking for some help writing the code? Or are you looking for someone to write it?
Copy link to clipboard
Copied
I‘m a complete novice so would need help writing it or if you could point me in the direction of ‘getting to know the basics‘ of Illustrator scripting. It’s something I’d really like to learn for myself.
Looking at other scripts out there for putting layers in alphabetical order I kinda understand it, but for what I’m looking to do I’m thinking I’d need to base it on the position of the vector based on its x and y position?
Copy link to clipboard
Copied
do you have any programming experience? just so i know where to start pointing you.
basic procedure for what you're looking to do would be this:
gather the items that need to be sorted (the swatch squares in your screenshot above).
sort the items by their y (or top) coordinate and place the sorted results into a new array
loop the sorted array to organize the items in the layers panel
(you could do this eitehr with zOrderPosition or with a simple bring to front or send to back command)
the above might actually live inside it's own function so that you can just feed it any kind of layer (top level or sublayer).
Depending upon how clean and predictable your file will be, this could be a very easy task, or a complicated process designed to filter out potential errors. There's no way to know really without looking at the file(s)
Copy link to clipboard
Copied
I don't have any programming experience. I've managed to add pre made scripts and tweak them a little. Other than that, none I'm afraid.
The files will always be exactly as my above screen shot.
Copy link to clipboard
Copied
Ok. if you have no programming experience as yet, you'll probably want to start with a basic javascript tutorial. I usually recommend codecademy.com. (it's free!)
If you go through their javascript "course" you'll get a decent understanding of basic syntax and programming logic. After that it would be time to start taking a look at the Illustrator JavaScript API to learn how to utilize the logic you learned to manipulate illustrator. Any specific questions you have, i'm more than happy to answer. But i'd start at codecademy first if you intend to learn how to write scripts for illustrator.
good luck. 😃
Copy link to clipboard
Copied
Thank you for your help and advice.
I've looked into several courses to learn JavaScript, but unfortunately its hugely outside of my understanding and I don't have the free time available to dedicate to it at the moment.
Thank you again for taking the time to read/reply to my post.
Copy link to clipboard
Copied
I had the same problem and I found working script in first massage here: Optimize objects stacking order for vinyl cutting.
Change BRINGTOFRONT to SENDTOBACK if you need to reverse order.