Copy link to clipboard
Copied
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
set placedPageNumber to PDF page number of PDF attributes of parentItem
for starters, this line won't work, you need to remove the first "PDF", the correct code is:
set placedPageNumber to page number of PDF attributes of parentItem
Copy link to clipboard
Copied
set placedPageNumber to PDF page number of PDF attributes of parentItem
for starters, this line won't work, you need to remove the first "PDF", the correct code is:
set placedPageNumber to page number of PDF attributes of parentItem
Copy link to clipboard
Copied
Hi Leo,
Sorry I had pasted the wrong code. The correct code is
#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();
Copy link to clipboard
Copied
However it worked it for Python too! Thx
Copy link to clipboard
Copied
i don't see anything in the new code you posted that would retrieve the page number of a placed pdf/ai file. you only retrieve link names, which won't include the page number. the correct code for what you need is still the one i posted above (convert it to js if needed).
Copy link to clipboard
Copied
Hi Leo,
No worries, you tip helped my first script. Now I am able to see in my first script the correct page of each link.
Thank you