AI Script – Sort Layers Alphabetically

Illustrator Script

Sort application active document 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);
    };
}

 

 

 

Shopping Cart