Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Script for renaming layer objects.

Participant ,
Apr 17, 2024 Apr 17, 2024

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

TOPICS
Scripting
1.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Apr 19, 2024 Apr 19, 2024

Hi @Steve25219687xhr4 , @Anantha Prabu G ’s code should work if you use allPageItems rather than layers. Something like this:

 

Screen Shot 2.png

 

Screen Shot 3.png

 

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
 
...
Translate
Engaged ,
Apr 17, 2024 Apr 17, 2024

Hi @Steve25219687xhr4 

Do you want to change rename only these layers?

Thanks,
Prabu
Design smarter, faster, and bolder with InDesign scripting.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Apr 17, 2024 Apr 17, 2024

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Apr 17, 2024 Apr 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!");
Thanks,
Prabu
Design smarter, faster, and bolder with InDesign scripting.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 18, 2024 Apr 18, 2024

Hi @Steve25219687xhr4,

Layers have unique name in InDesign. Can you share some screenshots of your layer panel to explain your ask better

-Manan

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Apr 19, 2024 Apr 19, 2024

Please find attached the requested sceen shot.

 

It is the layer objects I am hoping to rename.

i.e. 

API EDN Add heead 20 to 

API PAYTO Add heead 20

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 19, 2024 Apr 19, 2024

@Steve25219687xhr4 

 

How have you created all those layers?

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Apr 19, 2024 Apr 19, 2024

Not Layers. Layer objects inside the Layer

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 19, 2024 Apr 19, 2024
quote

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.

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 19, 2024 Apr 19, 2024
LATEST

Hi @Steve25219687xhr4 , @Anantha Prabu G ’s code should work if you use allPageItems rather than layers. Something like this:

 

Screen Shot 2.png

 

Screen Shot 3.png

 

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!");
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines