Skip to content

Instantly share code, notes, and snippets.

@milligramme
Created June 22, 2011 08:45
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save milligramme/1039713 to your computer and use it in GitHub Desktop.
Save milligramme/1039713 to your computer and use it in GitHub Desktop.
for Illustrator Sorting Layers
#target "Illustrator"
/**
* sort layers (with sublayer)
*/
var doc = app.documents[0];
var lay = doc.layers;
var array_primary = [];
for (var i=0, iL=lay.length; i < iL ; i++) {
if (lay[i].layers.length === 0) {
array_primary.push( lay[i].name );
}
else {
array_primary.push( lay[i].name );
var array_secondary = [];
for (var j=0, jL=lay[i].layers.length; j < jL ; j++) {
array_secondary.push(lay[i].layers[j].name);
};
var result2 = array_secondary.sort( function (a,b) { return a > b });
// sort sublayers
sort_layer (lay[i], result2);
}
};
var result1 = array_primary.sort( function(a,b) { return a > b } );
// sort layers
sort_layer (doc, result1);
function sort_layer (obj, array) {
for (var ri=0, riL=array.length; ri < riL ; ri++) {
obj.layers.getByName(array[ri]).zOrder( ZOrderMethod.SENDTOBACK );
};
}
@captainfodder
Copy link

Hey Milligramme,

Thank you for making this script, it's a step in a great direction. One question though: Is there any way for this script to sort the bottom most layer, or the layer with the object on it?

Basically what I'm trying to achieve is a layer group by state, then by provider, then by city, then the dot representing the city.
Example:

  • Wyoming
    -- Charter
    --- Cable
    ---- Gillette, WY
    ---- Casper, WY
    ---- Albin, WY

That above script so far will sort everything except the final (deepest) layer, the one with the object (my dot). So my Cities are still unsorted alphabetically. I've tried moving them to the top level just in-case they were too "deep" in the layering, but that didn't make any difference.

Thanks

@captainfodder
Copy link

Hey Milligramme,

I've found a way to sort the pathItems within Adobe Illustrator:

@wombatinua
Copy link

МАМКУ ТВОЮ ЕБАЛ

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment