Skip to content

Instantly share code, notes, and snippets.

@KennyRedman
Last active October 1, 2022 18:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KennyRedman/b8582079dabc1be17b05 to your computer and use it in GitHub Desktop.
Save KennyRedman/b8582079dabc1be17b05 to your computer and use it in GitHub Desktop.
Adobe Illustrator script that reorders all visible layers alphabetically
#target illustrator
main();
function main(){
if(!documents.length) return;
var doc = app.activeDocument;
var allLayers = app.activeDocument.layers;
var visibleLayers = [];
for(a=0; a<allLayers.length; a++){
var ilayer = allLayers[a];
if (ilayer.visible) {
visibleLayers.push(ilayer);
}
};
var alphabetizedLayers = visibleLayers.sort( function(a,b) { return a > b } );
sort_layers(doc, alphabetizedLayers);
}
function sort_layers(obj, abcLayers) {
for (var ri=0; ri<abcLayers.length;ri++) {
abcLayers[ri].zOrder(ZOrderMethod.SENDTOBACK);
};
}
@ScribbleGhost
Copy link

How do you use this in Illustrator?

@kredman
Copy link

kredman commented Sep 30, 2022

How do you use this in Illustrator?

Save the file somewhere and run it with Flie>Scripts>Other Scripts

@ScribbleGhost
Copy link

Thanks. That is what I did. But it does not seem to do anything in Illustrator 26.3.

@kredman
Copy link

kredman commented Oct 1, 2022

Thanks. That is what I did. But it does not seem to do anything in Illustrator 26.3.

It’s been a while since I wrote that and I don’t have access to Illustrator anymore to test it out unfortunately. Sorry.

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