Copy link to clipboard
Copied
I have script. wich sort layers by abc order.
#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.layers.length === 0) {
array_primary.push( lay.name );
}
else {
array_primary.push( lay.name );
var array_secondary = [];
for (var j=0, jL=lay.layers.length; j < jL ; j++) {
array_secondary.push(lay.layers
.name); };
var result2 = array_secondary.sort( function (a,b) { return a > b });
// sort sublayers
sort_layer (lay, 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 );
};
}
For example i have layer names:
Layer # 116
Layer # 12
Layer # 117
Layer # 32
Layer # 3
This script sorting them like:
Layer # 116
Layer # 117
Layer # 12
Layer # 3
Layer # 32
But i want to make it to increasing:
Layer # 3
Layer # 12
Layer # 32
Layer # 116
Layer # 117
Please, help me to make it right!
Ch ch ch check it out!
The sorting function is changed to take out non-numeric characters and then parse int to be able to sort by number vs string.
...#target illustrator-20
function test(){
/**
* sort layers (with sublayer)
*/
function sortNumeric(a, b){
a = a.replace(/[^\d]+/g, '');
b = b.replace(/[^\d]+/g, '');
return parseInt(a) > parseInt(b);
};
var doc = app.documents[0];
var lay = doc.layers;
var array_primary = [];
for (var i=0, iL=lay.length; i < iL ; i++) {
if (l
Copy link to clipboard
Copied
Ch ch ch check it out!
The sorting function is changed to take out non-numeric characters and then parse int to be able to sort by number vs string.
#target illustrator-20
function test(){
/**
* sort layers (with sublayer)
*/
function sortNumeric(a, b){
a = a.replace(/[^\d]+/g, '');
b = b.replace(/[^\d]+/g, '');
return parseInt(a) > parseInt(b);
};
var doc = app.documents[0];
var lay = doc.layers;
var array_primary = [];
for (var i=0, iL=lay.length; i < iL ; i++) {
if (lay.layers.length === 0) {
array_primary.push( lay.name );
}
else {
array_primary.push( lay.name );
var array_secondary = [];
for (var j=0, jL=lay.layers.length; j < jL ; j++) {
array_secondary.push(lay.layers
.name); };
var result2 = array_secondary.sort( sortNumeric);
// sort sublayers
sort_layer (lay, result2);
}
};
var result1 = array_primary.sort( sortNumeric );
// 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 );
};
}
};
test();
Copy link to clipboard
Copied
Dear Silly-V!
U giving me a hand again! I glad to know u, as good man and amazing script ninja!
Thank u very much, it works!