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

Indesign server version script which is better to use to access a links

Explorer ,
May 08, 2024 May 08, 2024

Copy link to clipboard

Copied

I am writing script for Adobe indesign server 2023 to access the links which code is better.
can anyone tell me the methods count() and property length difference or which is better for server version script .
below code  with length property
var documentLinks = app.documents[0].links;
for (stLnks = 0; stLnks < documentLinks.length; stLnks++){
documentLinks[stLnks].unlink();
}

below code  with count property
var documentLinks = myDoc.links;
for (stLnks = 0; stLnks < documentLinks.count(); stLnks++){
documentLinks[stLnks].unlink();
}

TOPICS
Bug , Import and export , Performance , Scripting , SDK , UXP Scripting

Views

116

Translate

Translate

Report

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 ,
May 09, 2024 May 09, 2024

Copy link to clipboard

Copied

.length or .count() -- it makes no difference. What does make a difference is using 

 

var documentLinks = app.documents[0].links.everyItem().getElements();

 

(instead of var documentLinks = app.documents[0].links). 

 

With var documentLinks = app.documents[0].links; you use a collection, while .everyItem().getElements(); converts the collection to an array, which almost always processes much quicker.

Votes

Translate

Translate

Report

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 ,
May 09, 2024 May 09, 2024

Copy link to clipboard

Copied

Thanks @Peter Kahrel

"Some time when I am using the .count() method in InDesign Server, it's not embedding links properly. However, when I am using .length one by one, all the links embed properly.

So, I have a doubt: count() is a method and length is a property. When can I use count() and when can I use length?"



Votes

Translate

Translate

Report

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 ,
May 09, 2024 May 09, 2024

Copy link to clipboard

Copied

LATEST

I have a doubt: count() is a method and length is a property. When can I use count() and when can I use length?

 

Well, I always use length, on bith Desktop and Server, and I've never seen a problem. So I would say use length and you can't go wrong. Why count() sometimes gives a problem I've no idea.

Votes

Translate

Translate

Report

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 ,
May 09, 2024 May 09, 2024

Copy link to clipboard

Copied

Hi samy@123 As @Peter Kahrel explained links are a collection and not an array—collections and arrays have different methods. You can find the links collection’s methods here:

 

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Links.html

 

Screen Shot 12.png

 

Also as Peter notes you can force a collection into an Array via getElements()—in that case you would not be able to use the collection methods

 

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Array.html

 

In your example using a collection would let you avoid the for loop—this single line would embed all of the document links:

 

 

 

 

var documentLinks = app.documents[0].links.everyItem().unlink()

 

 

 

Votes

Translate

Translate

Report

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