Skip to main content
Participant
December 16, 2022
Question

Problem with script

  • December 16, 2022
  • 3 replies
  • 681 views

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!:)

 

This topic has been closed for replies.

3 replies

Community Expert
December 17, 2022

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

Loic.Aigon
Legend
December 16, 2022

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

Community Expert
December 16, 2022

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

-Manan
Loic.Aigon
Legend
December 16, 2022

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 😉

Community Expert
December 16, 2022

var style=app.documents.paragraphStyles.item("texto justificado");

should be

var style=app.documents[i].paragraphStyles.item("texto justificado");

-Manan

-Manan
Participant
December 16, 2022

Thanks, Manan, that works.