Home > OS >  A Script To Sort Objects Alphabetically Within A Layer In Adobe Illustrator CC?
A Script To Sort Objects Alphabetically Within A Layer In Adobe Illustrator CC?

Time:09-16

I'm not literate about programming but I desperately need a script to help me sort alphabetically objects in a layer in Adobe Illustrator. My vector is a map having 1 layer with all the objects I need to sort at the same level. 1 These objects will be essentially paths, compound paths and groups. The ideal outcome is to sort the selected objects alphabetically. But any script that does the job is welcome.

In my investigation, I just found the same question from the Adobe Community but the scripts available in this page (https://community.adobe.com/t5/illustrator-discussions/how-to-sort-objects-alphabetically-inside-of-a-layer/m-p/6521187) end up with some errors like "No such... ". So, I hope this will help my helper as I don't know how to fix the problem from these scripts.

Oh thou God of my salvation, Emperor of JS language, please hear my prayer! :) [The image illustrates how my vector is organized]

Thanks in you in advance for trying to help me out with this!

CodePudding user response:

As far as I can see from the screenshot the 'West Sussex' is a group.

You can try to select the group and run this script:

var group = app.selection[0];
var len = group.pageItems.length;

for (var j=0; j<len; j  ) {
    var items = [];
    for (var i=0; i<group.pageItems.length; i  ) items.push(group.pageItems[i]);

    for (var i=0; i<items.length-1; i  ) {
        if (items[i].name > items[i 1].name) {
            items[i].move(items[i 1], ElementPlacement.PLACEAFTER);
            i  ;
        }
    }
}

The code is not exactly a best practice but it looks like it does the job.

CodePudding user response:

thank you for your help! It does the job perfectly and very fast! Answer validated for me. :)

  • Related