Script to list other pages from a link
Hello,
Im trying to create a script where it lists all links in the file. It works fine, but when I have a link with multiple pages placed, it doesnt like the other pages.
For example, if I have a File.ai with page 1 and page 2 placed, links panel shows me:
File.ai
File.ai:2
But my script can't list the page 2 like that, it shows me twice "FIle.ai"
Here is my script:
#target "InDesign"
function showDocumentSelection() {
var docNames = [];
for (var i = 0; i < app.documents.length; i++) {
docNames.push(app.documents[i].name);
}
// Create a window for document selection
var w = new Window("dialog", "Select an InDesign Document");
var docList = w.add("dropdownlist", undefined, docNames);
docList.selection = 0;
var okButton = w.add("button", undefined, "OK");
okButton.onClick = function() {
var selectedDoc = app.documents[docList.selection.index];
w.close();
showLinksInDocument(selectedDoc);
}
w.show();
}
function showLinksInDocument(doc) {
var links = doc.links;
var linkNames = [];
for (var i = 0; i < links.length; i++) {
linkNames.push(links[i].name);
}
if (linkNames.length > 0) {
// Create a window to list all links
var linkWindow = new Window("dialog", "Links in Document: " + doc.name);
var linkList = linkWindow.add("listbox", undefined, linkNames, {multiselect: false});
linkList.size = [400, 300];
var closeButton = linkWindow.add("button", undefined, "Close");
closeButton.onClick = function() {
linkWindow.close();
}
linkWindow.show();
} else {
alert("No links found in the document.");
}
}
showDocumentSelection();
Any idea?
Thank you
Danilo
