Skip to main content
Inspiring
April 17, 2024
Answered

Script for renaming layer objects.

  • April 17, 2024
  • 9 replies
  • 1187 views

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

This topic is closed to new replies. Start a new post to keep the conversation going.
Correct answer rob day

Not Layers. Layer objects inside the Layer


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!");

9 replies

Anantha Prabu G
Legend
April 17, 2024

Hi @Steve25219687xhr4 

Do you want to change rename only these layers?

Design smarter, faster, and bolder with InDesign scripting.
Inspiring
April 17, 2024

All instances of these layer objects, there is quite a few

Anantha Prabu G
Legend
April 17, 2024
// 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!");
Design smarter, faster, and bolder with InDesign scripting.