-
1. Re: batch change names of the buttons?
Mi_D Mar 14, 2014 2:36 AM (in response to Petteri_Paananen)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[i].constructor.name);
if (items[i].constructor.name=="Button"){
items[i].name ="Button";
}
}
Mi_D
-
2. Re: batch change names of the buttons?
[Jongware] Mar 14, 2014 2:38 AM (in response to Petteri_Paananen)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[x].name = 'Button '+String(x);
where [x] is taken from some sort of list of buttons; but how to create that list depends on where the buttons reside.
-
3. Re: batch change names of the buttons?
Petteri_Paananen Mar 14, 2014 3:25 AM (in response to [Jongware])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.
-
4. Re: batch change names of the buttons?
Mi_D Mar 14, 2014 3:25 AM (in response to Petteri_Paananen)remove alert or comment
// alert(items[i].constructor.name);
Mi_D
-
5. Re: batch change names of the buttons?
Petteri_Paananen Mar 14, 2014 3:34 AM (in response to Mi_D)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?
-
6. Re: batch change names of the buttons?
Mi_D Mar 14, 2014 3:57 AM (in response to Petteri_Paananen)HI,
Peterin I check in deifferent layer it's working fine
send ur indd file
Mi_D
-
7. Re: batch change names of the buttons?
Petteri_Paananen Mar 14, 2014 4:31 AM (in response to Mi_D)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)
-
8. Re: batch change names of the buttons?
Petteri_Paananen Mar 14, 2014 8:32 AM (in response to Petteri_Paananen)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[i].constructor.name);
if (items[i].constructor.name=="Button"){
items[i].name ="button";
}
}
alert("Page done.");
-
9. Re: batch change names of the buttons?
Mi_D Mar 14, 2014 8:59 PM (in response to Petteri_Paananen)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[p].pageItems.everyItem().getElements();
for (var i=0; items.length>i; i++){
if (items[i].constructor.name=="Button"){
items[i].name ="button";
}
}
}
Mi_D
-
10. Re: batch change names of the buttons?
Petteri_Paananen Mar 16, 2014 6:17 AM (in response to Mi_D)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.



