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

batch change names of the buttons?

Guide ,
Mar 14, 2014 Mar 14, 2014

Hi!

I have an InDesign file with lots of buttons... with different names... now I should change the names of all buttons to be just "button"... I suppose it´s super easy with scripting but I just can´t get it to work (I´m really newbie with scripting)

petteri

TOPICS
Scripting
1.7K
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

Contributor , Mar 14, 2014 Mar 14, 2014

hi Petteri,

privious post i not add page loop so it change in 1st page only try now

var myDoc = app.activeDocument;

var pages = myDoc.pages;

    for (var p=0; pages.length>p; p++)

    {

         var items = pages

.pageItems.everyItem().getElements();

            for (var i=0; items.length>i; i++){

                       if (items.constructor.name=="Button"){

                        items.name ="button";

           }

       }

}

Mi_D

Translate
Contributor ,
Mar 14, 2014 Mar 14, 2014

try below code

var myDoc = app.activeDocument;

var pages = myDoc.pages;

  var items = pages[0].pageItems.everyItem().getElements();

  for (var i=0; items.length>i; i++){

       alert(items.constructor.name);

       if (items.constructor.name=="Button"){

            items.name ="Button";

           }

      }

Mi_D

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 ,
Mar 14, 2014 Mar 14, 2014

According to the Object Model Viewer, the parent of a Button is one of the text items (see the hierarchy diagram on http://jongware.mit.edu/idcs6js/pc_Button.html), or it's placed immediately on to a page or spread. Did you use only one way, or possibly both?

Apart from that, it should be as easy as

button.name = 'Button '+String(x);

where is taken from some sort of list of buttons; but how to create that list depends on where the buttons reside.

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
Guide ,
Mar 14, 2014 Mar 14, 2014

Thanks to both of you...=)

@Mi_D

Is that alert required, there´s aprx. 40000 objects in that document so.... you know....=)

[Jongware]

Thanks, I have to check that out, it may go a bit over my skills tough... as I mentioned this is all pretty new to me... but I will sure give it a try.

Buttons in that document have been placed all over the pages. Most of them are buttons with go to URL action, and copy/pasted from one button named link, so they are basically all named like link 23, link 48, link 77 etc.... I guess InDesign adds that running number to the name when you duplicate a button.

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
Contributor ,
Mar 14, 2014 Mar 14, 2014

remove alert or comment

  //  alert(items.constructor.name);

Mi_D

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
Guide ,
Mar 14, 2014 Mar 14, 2014

Ok, now I tried it but for some reason it does not change the names of my buttons... could it be because they are in different layers? Does that script work only if all the buttons are in same 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
Contributor ,
Mar 14, 2014 Mar 14, 2014

HI,

Peterin I check in deifferent layer it's working fine

send ur indd file

Mi_D

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
Guide ,
Mar 14, 2014 Mar 14, 2014

I think it has something to do with the number of buttons. If I try it to some smaller document with few buttons it works, but if number of converted buttons is large... it doesn´t...

here´s one indd with lots of buttons (pink rectangles)

https://dl.dropboxusercontent.com/u/17227987/linktest_2.indd  (InDesign CC)

https://dl.dropboxusercontent.com/u/17227987/linktest_2.idml (for older InDesigns)

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
Guide ,
Mar 14, 2014 Mar 14, 2014

I changed the script to convert buttons on active page only instead of all pages and it seems to work... as far as I have selected some page to be active in Pages Panel... so I guess there´s nothing wrong with actual conversion.

======

var myDoc = app.activeDocument;

var pages = app.activeWindow.activePage;

  var items = pages.pageItems.everyItem().getElements();

for (var i=0; items.length>i; i++){

       //alert(items.constructor.name);

       if (items.constructor.name=="Button"){

            items.name ="button";

           }

}

alert("Page done.");

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
Contributor ,
Mar 14, 2014 Mar 14, 2014

hi Petteri,

privious post i not add page loop so it change in 1st page only try now

var myDoc = app.activeDocument;

var pages = myDoc.pages;

    for (var p=0; pages.length>p; p++)

    {

         var items = pages

.pageItems.everyItem().getElements();

            for (var i=0; items.length>i; i++){

                       if (items.constructor.name=="Button"){

                        items.name ="button";

           }

       }

}

Mi_D

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
Guide ,
Mar 16, 2014 Mar 16, 2014
LATEST

That works beautifully, thanks a lot. I added only a small counter and alert that tells user when conversion is ready and how many button names were converted....

Thanks for Jongware too, I will check out your link too. I want to know what´s going on under the hood.

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