Copy link to clipboard
Copied
Dear people,
Perhaps you know how should look like the script changing thae names of all layers to random ones?
When I export a GeoPDF the software wants from me the names of the layers should be different from each other. For now I have someting like "Layer 1, Layer 1, Layer 1..."
It can be even such names as "hjbjhgdsdklahf". Completely different characters, but random. Just every layer needs to have different name from the others.
When it is not so many of them, I can change them manually, but when there is more layers...
Thank you for your thoughts,
2 Correct answers
Hello,
You can try the following script that will rename layers to Layer 1, Layer 2, Layer 3 and so on.
var _doc = app.documents[0];
var _layers = _doc.layers
for (var l = 0; l < _layers.length; l++) {
_layers[l].name = 'Layer ' + (l + 1);
}
Note: It will not rename the sublayers.
var layers = app.activeDocument.layers;
for (var i = 0; i < layers.length; i++) {
var string1 = "";
for (var j = 0; j < 10; j++) {
var n = Math.floor(Math.random() * 24) + 97;
string1 += String.fromCharCode(n);
}
layers[i].name = string1;
}
Explore related tutorials & articles
Copy link to clipboard
Copied
There are already scripts that can do it. For example, I'd recommend "RenameItems", provided by Sergey Osokin.
Copy link to clipboard
Copied
Hello,
You can try the following script that will rename layers to Layer 1, Layer 2, Layer 3 and so on.
var _doc = app.documents[0];
var _layers = _doc.layers
for (var l = 0; l < _layers.length; l++) {
_layers[l].name = 'Layer ' + (l + 1);
}
Note: It will not rename the sublayers.
Copy link to clipboard
Copied
Thank you guys, all of you, for help.
Works like a gold.
No need to worry about sublayers.
Copy link to clipboard
Copied
var layers = app.activeDocument.layers;
for (var i = 0; i < layers.length; i++) {
var string1 = "";
for (var j = 0; j < 10; j++) {
var n = Math.floor(Math.random() * 24) + 97;
string1 += String.fromCharCode(n);
}
layers[i].name = string1;
}
Copy link to clipboard
Copied
I am not familar with GeoPDF, so I don't know if this will be pertanent or not. There is a Preference under Units, to "Identify Object By" and if you choose XML ID each layer becomes unique. Just not sure how it works when saving as or exporting as PDF.

