Skip to main content
Known Participant
September 18, 2024
Answered

Script to list other pages from a link

  • September 18, 2024
  • 1 reply
  • 419 views

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

This topic has been closed for replies.
Correct answer leo.r
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

1 reply

leo.r
Community Expert
leo.rCommunity ExpertCorrect answer
Community Expert
September 18, 2024
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
Known Participant
September 19, 2024

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();

Known Participant
September 19, 2024

However it worked it for Python too! Thx