Copy link to clipboard
Copied
Hi all,
I have an illustrator scripting question that I am unable to find help on anywhere.
I have multiple layers with one or more items in each layer. Each layer has a meaninful name but the items within the layers do not(they are not sub-layers, they are items such as rectangles, lines etc.)
I need to rename the items in each layer with the same name as the parent layer. If there are multiple items within a layer, they all need the same name as the layer that they are a member of.
If anyone could point me towards anything that will do this I'd be really grateful.
Many thanks.
Hello, That can be done easily, First you need to traverse all layers present in the document and then, you traverse all pageItems inside the layers and assign name of the parent layer. Here is the small sample script that will help you to this.
var layers = app.activeDocument.layers;
for (var i = 0; i < layers.length; i++) {
var layerName = layers[i].name;
for (var j = 0; j < layers[i].pageItems.length; j++) {
layers[i].pageItems[j].name = layerName;
}
}
This script will not
...Copy link to clipboard
Copied
Hello, That can be done easily, First you need to traverse all layers present in the document and then, you traverse all pageItems inside the layers and assign name of the parent layer. Here is the small sample script that will help you to this.
var layers = app.activeDocument.layers;
for (var i = 0; i < layers.length; i++) {
var layerName = layers[i].name;
for (var j = 0; j < layers[i].pageItems.length; j++) {
layers[i].pageItems[j].name = layerName;
}
}
This script will not name the items that are inside the groups. Hope this helps you to start the script.
Copy link to clipboard
Copied
Wow that is awesome, thank you so much!! Are you on peopleperhour or similar?
Copy link to clipboard
Copied
Your welcome 🙂 DM you.