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

Script for renaming layer objects.

Explorer ,
Apr 17, 2024 Apr 17, 2024

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

TOPICS
Scripting

Views

510

Translate

Translate

Report

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
 
...

Votes

Translate

Translate
Engaged ,
Apr 17, 2024 Apr 17, 2024

Copy link to clipboard

Copied

Hi @Steve25219687xhr4 

Do you want to change rename only these layers?

Thanks,
Prabu
Design smarter, faster, and bolder with InDesign scripting.

Votes

Translate

Translate

Report

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
Explorer ,
Apr 17, 2024 Apr 17, 2024

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

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!");
Thanks,
Prabu
Design smarter, faster, and bolder with InDesign scripting.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Hi @Steve25219687xhr4,

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

-Manan

Votes

Translate

Translate

Report

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
Explorer ,
Apr 19, 2024 Apr 19, 2024

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

@Steve25219687xhr4 

 

How have you created all those layers?

 

Votes

Translate

Translate

Report

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
Explorer ,
Apr 19, 2024 Apr 19, 2024

Copy link to clipboard

Copied

Not Layers. Layer objects inside the Layer

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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.

 

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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