Help with creating a script to make renaming layer objects faster

Community Beginner ,
Apr 23, 2021 Apr 23, 2021

Copy link to clipboard

Copied

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

Views

183

Likes

translate

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

Adobe Community Professional , 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;...

Likes

translate

Translate

Translate
Adobe Community Professional ,
Apr 23, 2021 Apr 23, 2021

Copy link to clipboard

Copied

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.

 

Likes

translate

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

Copy link to clipboard

Copied

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! 

Likes

translate

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

Copy link to clipboard

Copied

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?

Likes

translate

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

Copy link to clipboard

Copied

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.

 

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

 

 

 

 

Likes

translate

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

Copy link to clipboard

Copied

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 @brianp311. And thanks for the extra detail Rob! 

 

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

 

 

Likes

translate

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

Copy link to clipboard

Copied

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++;
   }
} 

 

Likes

translate

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

Copy link to clipboard

Copied

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++
        };   
    }  
};   

Likes

translate

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