Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Script to list other pages from a link

Explorer ,
Sep 18, 2024 Sep 18, 2024

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

TOPICS
Scripting
262
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Sep 18, 2024 Sep 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
Translate
Community Expert ,
Sep 18, 2024 Sep 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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 19, 2024 Sep 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();

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 19, 2024 Sep 19, 2024

However it worked it for Python too! Thx

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 19, 2024 Sep 19, 2024

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).

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 19, 2024 Sep 19, 2024
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines