Hi, is there a quick way how to renumber or batch rename all layers in a file so they would be named in consequent numbers? Doesn't have to start from exact number, I was wondering if maybe there is some sort of script that would help me with that? Thanks Pavel
Thank you for the script. It is very useful.
Could you help me with one thing? If I want to add letters "ca" in front of the number, where should I add "ca" and how to do that?
The present script is 1, 2, 3, 4... on each layer.
I want the script to be ca1, ca2, ca3, ca4... on each layer.
Please help me out.
I have a script that exports each top layer to a JPG, while all layers named ALWAYS are combined with it (for webdesign screens, the ALWAYS layer usually contains a browser background image, main menu, and other recurring elements).
http://supermetricity.com/2009/02/11/save-layers-as-jpgs-from-illustra tor/
I've been trying to combine the rename script with my export script, but with little success.
Ideally, the export script would name the jpgs it makes from the top layers from the bottom up, adding numbers "01" +n befroe the original layer name, and the layer(s) called ALWAYS would not be exported as single JPG at all...
if that's too complex, is there a way to just not rename any layers called ALWAYS in your rename script?
Not too sure if this is what you meant or if this is the best way but I tried…
#target illustrator
var docRef = app.activeDocument;
with (docRef) {
var myNumber = 1;
for (var i = layers.length-1; i >= 0; i--) {
if (layers[i].name != 'ALWAYS') {
layers[i].name = myNumber + 'n ' + layers[i].name;
myNumber = myNumber + 1;
continue;
}
}
myNumber = 1;
}
Should number from bottom up skipping layers names 'ALWAYS'
fantastic, thanks so much!
that's what I actually tweaked it to now:
#target illustrator
var docRef = app.activeDocument;
with (docRef) {
var myNumber = 1;
for (var i = layers.length-1; i >= 0; i--) {
if (layers[i].name != 'ALWAYS') {
layers[i].name = myNumber + '-' + activeDocument.name;
myNumber = myNumber + 1;
continue;
}
}
myNumber = 1;
}
docRef is a reference to the activeDocument so while we are inside of the with (docRef) {doStuffHere} you don't need to mention it again… Just use 'name'. This should check the layers length as string to count the required zero padding…
#target illustrator
var docRef = app.activeDocument;
with (docRef) {
var myNumber = 1;
for (var i = layers.length-1; i >= 0; i--) {
var x = layers.length.toString().length;
var z = zeroPad(myNumber, x);
if (layers[i].name != 'ALWAYS') {
layers[i].name = z + '-' + name;
myNumber = myNumber + 1;
continue;
}
}
// myNumber = 1;
}
function zeroPad(num, digit) {
var tmp = num.toString();
while (tmp.length < digit) {tmp = '0' + tmp;}
return tmp;
}
Thanks Mark!
works perfect now, I had to make a small adjustment though, and set digit to 2...see below:
#target illustrator
var docRef = app.activeDocument;
with (docRef) {
function zeroPad(num) {
Ooh, that could work Larry. I'm tied up with other work so I can't do too much research right now.
How would I address visible layers only? Would it be in this initial statement?
Instead of:
var docRef = app.activeDocument;
It might be:
var docRef = app.activeDocument.visibility.true;
(im sure that syntax is not correct for visibility -- any advice on that attribute would be much appreciated)
thanks in advance!
Kevin,
Your guess would only test if the active document is visible
But at least you got the right property name!
What Larry says; you need to test "visible" per layer. I don't have the opportunity to test it right now, but here is the last script from this thread, with a "visible" test blatantly injected where it seemed appropriate:
(I see a couple of odd programming 'choices' in this script but it might be because it evolved throughout the discussion -- a total rewrite would oblige me to test it before posting ...)
#target illustrator
var docRef = app.activeDocument;
with (docRef) {
var myNumber = 1;
for (var i = layers.length-1; i >= 0; i--) {
if (layers[i].visible == true) // <--- Testing .. 1,2,3.
{
var x = layers.length.toString().length;
var z = zeroPad(myNumber);
if (layers[i].name != 'ALWAYS') {
if (layers[i].name != 'GRID') {
layers[i].name = z + '-' + name;
myNumber = myNumber + 1;
continue;
}
}
}
}
// myNumber = 1;
}
function zeroPad(num) {
var tmp = num.toString();
while (tmp.length < 2) {tmp = '0' + tmp;}
return tmp;
}
North America
Europe, Middle East and Africa
Asia Pacific