Skip to main content
samy@123
Inspiring
May 9, 2024 6:57 AM UTC
Question

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

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

This topic is closed to new replies. Start a new post to keep the conversation going.

4 replies

rob day
Community Expert
Community Expert
May 9, 2024 10:41 AM UTC

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

 

 

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

 

 

 

Translate
Peter Kahrel
Community Expert
Community Expert
May 9, 2024 8:07 AM UTC

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

Translate
samy@123
samy@123Author
Inspiring
May 9, 2024 8:50 AM UTC

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?"



Translate
Peter Kahrel
Community Expert
Community Expert
May 9, 2024 2:39 PM UTC

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

Translate