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

Help with creating a script to make renaming layer objects faster

Community Beginner ,
Apr 23, 2021 Apr 23, 2021

Hello

 

As a frequent user of InDesign, I've been finding the limited functionality and slowness to rename objects within a layer a pain. Compared to other Adobe products like Premiere Pro, where you can press the spacebar to easily rename layers, InDesign is slow and painful.

 

I've reached out to the customer service support many times with no avail to help this issue. I was recently told that "For assistance with exact script, you should post your query on Adobe Support Community, an expert from Adobe Engineering Team should be able to help" so I'm looking for help here. 

 

With some research, I found multiple forums that support the idea that a script can be created to overcome the renaming issue. The scripts allow a batch rename of layers or objects within a layer all at once, so it doesn't need to be done manually. 

Here are some links to those forums:

 

In my case, I would like the objects within a layer to be easily renamed using the script.

 

In the screenshot below, you can see six objects with the name <One>. I would like the script to rename these layers to:

100

101

102

103

104

105

106

 

Screen Shot 2021-04-24 at 10.06.54 am.png

 

I am not a script writing guru, but can follow instruction well. Please help with this as it's a huge efficiency issue for me, as I can have hundreds of objects which I currently need to rename manually. The renaming of these objects is important as I frequently use buttons for interactive forms, so the "Set Tab Order..." function is crucial. It would be worlds easier if the script could rename these objects for me, so all I need to do is make sure they are placed in the correct order under the Layer.

 

Hopefully this makes sense, but please let me know if it doesn't as I can answer any required questions.

 

Please help me! Any assistance is greatly appreciated.

 

Thanks

Lou

TOPICS
Scripting
1.5K
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 23, 2021 Apr 23, 2021

Renaming layer items just requires a triple click, but,

This will do it to every layer in the document, and only the top level page item in the document (ie won't change name of text frames that are grouped).

If you don't like that, change the first line to :

    var docLayers = [app.activeDocuments.layers.itemByName("Layer 1")];

I guess I'm an Adobe Engineering Expert now... 

 

var docLayers = app.activeDocument.layers.everyItem().getElements();
var aLayer, i, j, layerPageItems, numLPIs, count;
...
Translate
Community Expert ,
Apr 23, 2021 Apr 23, 2021

Renaming layer items just requires a triple click, but,

This will do it to every layer in the document, and only the top level page item in the document (ie won't change name of text frames that are grouped).

If you don't like that, change the first line to :

    var docLayers = [app.activeDocuments.layers.itemByName("Layer 1")];

I guess I'm an Adobe Engineering Expert now... 

 

var docLayers = app.activeDocument.layers.everyItem().getElements();
var aLayer, i, j, layerPageItems, numLPIs, count;
for (i = 0; i < docLayers.length; i++) {
   aLayer = docLayers[i];
   layerPageItems = aLayer.pageItems.everyItem().getElements();
   numLPIs = layerPageItems.length;
   count = 100;
   for (j = 0; j < numLPIs; j++) {
       layerPageItems[j].name = count + "";
       count++;
   }
} 

 

You're welcome.

 

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 Beginner ,
Apr 24, 2021 Apr 24, 2021

Brian you are an absolute legend.

 

I copied your script to TextEdit, saved it in .jsx format (remembering to ensure there wasn't a sneaky .txt on the end too!), then added it into InDesign and it works like a charm. Honestly, I cannot thank you enough - this will save so much time for me!

 

Like magic!

loumuscolino_0-1619330485924.png

 

YAY! 

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 24, 2021 Apr 24, 2021

The items listed in a Layer are actually page items, so the list could change depending on the current active page. Sould the script handle page items on different pages—like Brian’s script— or would it only target the active page?

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 Beginner ,
Apr 24, 2021 Apr 24, 2021

Ah yes, I see what you mean here. I've just been testing it out and can see that the script renames page items on different pages the same name:

loumuscolino_0-1619331065499.png

loumuscolino_2-1619331354261.png

 

Would it be possible to separate this so only the active page with its page items will be renamed?

I'm aiming to rename from 100 onwards for Page 1, from 200 onwards for Page 2 and so on. If different pages have the same page item names as each other, this sometimes causes problems when creating interactive forms with buttons and text fields.

 

@brian_p_dts apologies Brian, would you please be able to help with this if possible?

 

 

 

 

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 Beginner ,
Apr 24, 2021 Apr 24, 2021

Actually, please ignore me!!

 

I've used the alternate script you provided in the initial post to resolve it.

 

This is where I got to in the end:

loumuscolino_0-1619332114407.png

 

Once again, a huge thank you Brian @brian_p_dts. And thanks for the extra detail Rob! 

 

I'm hoping this will be the last of my chaotic posts!! 

 

 

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 25, 2021 Apr 25, 2021

Glad it helped. To write something that you didn't have to edit for every page you could do something like this instead, targeting all items in a specific layer called Form. If layer didn't matter, just remove the if statement and make it look more like the original post. Note that this would miss pasterboard items. 

 

var pages = app.activeDocument.pages.everyItem().getElements();

var i, j, pis, numPIs, count;

for (i = 0; i < pages.length; i++) { 

    pis = pages[i].pageItems.everyItem(). getElements();

    numPIs = pis.length;

    count = (i + 1) * 100;

    for (j = 0; j < numPIs; j++) {

        if (pis[j].itemLayer.name == "Form") {

            pis[j].name = count + "";

            count++;

        }

    }

 

Ignore the original code below... I had pasted it in but am on mobile and can't remove it. 

 

var docLayers = app.activeDocument.layers.everyItem().getElements();
var aLayer, i, j, layerPageItems, numLPIs, count;
for (i = 0; i < docLayers.length; i++) {
   aLayer = docLayers[i];
   layerPageItems = aLayer.pageItems.everyItem().getElements();
   numLPIs = layerPageItems.length;
   count = 100;
   for (j = 0; j < numLPIs; j++) {
       layerPageItems[j].name = count + "";
       count++;
   }
} 

 

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 25, 2021 Apr 25, 2021

I'm aiming to rename from 100 onwards for Page 1, from 200 onwards for Page 2 and so on.

 

Do you mean like this:

 

Screen Shot.pngScreen Shot 1.pngScreen Shot 2.png

 

Then try this variation on Brian’s script:

 

var pgs = app.activeDocument.pages
var docLayers = app.activeDocument.layers
var j,k,n,li,cnt,doff;

for (var i = 0; i < pgs.length; i++){
    doff = pgs[i].documentOffset + 1;
    pgs[i].pageItems
    var ppi = pgs[i].pageItems
    for (j = 0; j < docLayers.length; j++){
        li = []
        for (k = 0; k < ppi.length; k++){       
            if (ppi[k].itemLayer == docLayers[j]) {
                li.push(ppi[k])
            } 
        }
        cnt = 100 * doff
        for (n = 0; n < li.length; n++){
            li[n].name = cnt + ""
            cnt++
        };   
    }  
};   
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
New Here ,
Apr 30, 2025 Apr 30, 2025

Is the a way to create a script that i could run when i create a new document to create and rename new layers

Top 1 Layer: Logo

2. Layer: TNC

3. Layer Image/ Text

4. Layer: Graphics

5. Layer: Background

So it creates 5 new layers and then names them to the names and order as above? 

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 30, 2025 Apr 30, 2025

Seems like on chatgpt could handle relatively easily but: 

 

var d = app.activeDocument; 

var ns = ["Logo","TNC","Image/ Text","Graphics","Background"];

var i = ns.length;

while(i--) {

 var l = d.layers.add();

  l.name = ns[i];

}

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 ,
May 01, 2025 May 01, 2025
LATEST

@Enrico280771757be0

 

Or you can create a Template document? 

 

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