Copy link to clipboard
Copied
Hi there,
To save me some time renaming every single layer object in an Indesign document, I was wondering if anyone had knowledge of a script that can be used to rename layer objects.
i.e.
"API EDN Add heead 13" to "API PAYTO Add heead 13".
Any help will be greatly appreciated.
Kind regards,
Steve
Hi @Steve25219687xhr4 , @Anantha Prabu G ’s code should work if you use allPageItems rather than layers. Something like this:
var nameMap = {
"API EDN Add heead 13": "API PAYTO Add heead 13",
"BCA": "AAA",
"ABD": "CCC"
};
// Access the active document
var doc = app.activeDocument;
var layer;
// Loop through all layers in the document
for (var i = 0; i < doc.allPageItems.length; i++) {
layer = doc.allPageItems[i];
// Check if the layer's name is in the nameMap
Copy link to clipboard
Copied
Do you want to change rename only these layers?
Copy link to clipboard
Copied
All instances of these layer objects, there is quite a few
Copy link to clipboard
Copied
// Define the mapping of old names to new names
var nameMap = {
"API EDN Add heead 13": "API PAYTO Add heead 13",
"BCA": "AAA",
"ABD": "CCC"
};
// Access the active document
var doc = app.activeDocument;
// Loop through all layers in the document
for (var i = 0; i < doc.layers.length; i++) {
var layer = doc.layers[i];
// Check if the layer's name is in the nameMap
if (nameMap[layer.name]) {
// Rename the layer using the nameMap
layer.name = nameMap[layer.name];
}
}
alert("Layer renaming complete!");
Copy link to clipboard
Copied
Layers have unique name in InDesign. Can you share some screenshots of your layer panel to explain your ask better
-Manan
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Not Layers. Layer objects inside the Layer
Copy link to clipboard
Copied
Not Layers. Layer objects inside the Layer
By @Steve25219687xhr4
That's what I've thought - there are no "Layer Objects" - just "Objects" - that are placed on "Layers".
You need completely different script than what @Anantha Prabu G prvided.
Copy link to clipboard
Copied
Hi @Steve25219687xhr4 , @Anantha Prabu G ’s code should work if you use allPageItems rather than layers. Something like this:
var nameMap = {
"API EDN Add heead 13": "API PAYTO Add heead 13",
"BCA": "AAA",
"ABD": "CCC"
};
// Access the active document
var doc = app.activeDocument;
var layer;
// Loop through all layers in the document
for (var i = 0; i < doc.allPageItems.length; i++) {
layer = doc.allPageItems[i];
// Check if the layer's name is in the nameMap
if (nameMap[layer.name]) {
// Rename the layer using the nameMap
layer.name = nameMap[layer.name];
}
}
alert("Layer renaming complete!");