Copy link to clipboard
Copied
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
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
where
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
remove alert or comment
// alert(items.constructor.name);
Mi_D
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
HI,
Peterin I check in deifferent layer it's working fine
send ur indd file
Mi_D
Copy link to clipboard
Copied
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)
Copy link to clipboard
Copied
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.");
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now