Problem with script
Copy link to clipboard
Copied
Hi,
I am trying to modify some properties from one paragraph syle, but when I execute the code below appears this error "JavaScript Error: Object does not support the property or method "paragraphStyles".
// code
for (i=0; i<app.documents.length; i++){
var style=app.documents.paragraphStyles.item("texto justificado");
style.justification = Justification.LEFT_ALIGN;
}
If anyone could can help me, it would be great!:)
Copy link to clipboard
Copied
var style=app.documents.paragraphStyles.item("texto justificado");
should be
var style=app.documents[i].paragraphStyles.item("texto justificado");
-Manan
Copy link to clipboard
Copied
Thanks, Manan, that works.
Copy link to clipboard
Copied
To complete Manan's answer, documents is a collection, i.e. a pseudo array of documents. When you call paragraphStyles property on this collection, it fails because paragraphStyles is actually a property of the Document object which is an instance of the Documents collection.
Hence Manan's answer, use the property on the specific instance through either :
…documents.item(n).paragrapStyles… or documents.item("myDoc.indd").paragrapStyles…;
…documents[n].paragrapStyles…
…documents.itemByName("myDoc.indd").paragrapStyles…
…documents.itemByID(12345).paragrapStyles…
all those properties details can be found here:
https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Documents.html#d1e55773
HTH
Loic
Copy link to clipboard
Copied
Thanks @Loic.Aigon for adding in the explanantion. I did not write it probably because I was feeling too lazy or maybe I thought that it was a typo that @davidr40577873 was just not looking at. However, you coming in and writing in a detailed explanation anyhow is very much appreciated.
-Manan
Copy link to clipboard
Copied
My pleasure @Manan Joshi I did think of the rookie me more than a decade ago taking a grip on those concepts. And the forum was a good place to start with alongside documentation 😉
Copy link to clipboard
Copied
It could also be that the snippet was copied from an old forum post where the iterators had been stripped.
Copy link to clipboard
Copied
Many thanks @Loic.Aigon for your accurate explanation. Now I need to know how to extend this script (modifyng the properties included the paragraph style) to ALL paragraph styles my indd includes.
Copy link to clipboard
Copied
Assuming none of the styles are in groups, you can accomplish everything with a single line:
app.documents.everyItem().paragraphStyles.everyItem().justification = Justification.LEFT_ALIGN;
Copy link to clipboard
Copied
While you wonder what this everyItem method is, that condensed the code to just a single line, you would be well served by reading a bit about it. A couple of brilliant article on it that almost all of us refer are listed below. Thank @Marc Autret for these invaluable gems
https://www.indiscripts.com/post/2010/06/on-everyitem-part-1
https://www.indiscripts.com/post/2010/07/on-everyitem-part-2
-Manan
Copy link to clipboard
Copied
"Now I need to know how to extend this script (modifyng the properties included the paragraph style) to ALL paragraph styles my indd includes."
Hi @davidr40577873 ,
the scope of item("Name") or itemByName("Name") when it comes to paragraph styles, character styles, table styles or cell styles is not as perfect as it might seem from your perspective. It does not reach into style groups! Also note that you cannot change the first paragraph style in the collection of paragraph styles, the "No Paragraph Style" style.
You'll reach all paragraph styles with the document's allParagraphStyles array and loop that beginning with the second item in the array:
// ExtendScript (JavaScript) SAMPLE CODE:
var allParaStylesOfDoc = app.documents[0].allParagraphStyles;
var allParaStylesOfDocLength = allParaStylesOfDoc.length;
for( var n=1; n<allParaStylesOfDocLength; n++ )
{
allParaStylesOfDo[n].justification = Justification.LEFT_ALIGN;
};
Warning: For various reasons discussed elsewhere in this forum it is good practice not to change the Basic Paragraph style of a document. So you would start the loop of paragraph styles with iterator number 2 instead. The Basic Paragraph Style is always the second one in the allParagraphStyles array of a document:
var n=2;
Regards,
Uwe Laubender
( Adobe Community Expert )

