Skip to main content
Known Participant
Sep 18, 2024 8:21 PM UTC
Answered

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

This topic is closed to new replies. Start a new post to keep the conversation going.
leo.r
leo.rCorrect answer
Community Expert
Sep 18, 2024 11:37 PM UTC
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

5 replies

leo.r
Community Expert
leo.rCommunity ExpertCorrect answer
Community Expert
Sep 18, 2024 11:37 PM UTC
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
Translate
Known Participant
Sep 19, 2024 7:55 AM UTC

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

Translate
Known Participant
Sep 19, 2024 8:05 AM UTC

However it worked it for Python too! Thx

Translate