Skip to main content
dublove
Legend
August 10, 2025
Answered

How do I apply paragraph styles from a paragraph style group?

  • August 10, 2025
  • 1 reply
  • 706 views

For example, my group name is: myGroup
It contains the paragraph style: mypar
How should I write this?

app.selection[0].texts[0].appliedParagraphStyle = mypar;

Thank you. 

Correct answer Manan Joshi

@dublove it is not about the approach @brian_p_dts took but about what are the possible approaches and there are not too many in this case. You need to locate the paragraphStyle to use it and there are two collections for that on the document object, namely

  • paragraphStyles :- However, this does not contain styles that are present in the group. So you can't use this. This collection has the benefit of methods like itemByName, itemByID etc. So if you can use it this is the best method.
  • allParagraphStyles :- This contains all the paragraph styles of the document irrespective of the group in which they are present. However, this is an array, so no special methods like itemByName. Only way to find anything in this would be iterating the array. Another point to note is that styles can have the same name inside different groups. So in order to exactly find the style in a particular group you will need to check it's group as well

So the approach that @brian_p_dts used is fine, else you can also try with allParagraphStyles. However, there is no straight method to get the styles in the group.

-Manan

1 reply

brian_p_dts
Community Expert
Community Expert
August 11, 2025

var mypar = app.activeDocument.paragraphStyleGroups.itemByName("myGroup").paragraphStyles.itemByName("mypar"); 

 

No offense friend, but in my learning journey, I would only come here when I was well and thoroughly stuck. You've been at this long enough to be familiar enough with the API to figure things out on your own, methinks. 

dublove
dubloveAuthor
Legend
August 11, 2025

HI brian_p_dts

Thank you very much.

Your approach seems different from what I imagined.
I thought there would be a simple form of myGroup (mypar)

app.selection[0].texts[0].appliedParagraphStyle =myGroup(mypar);

 

Manan JoshiCommunity ExpertCorrect answer
Community Expert
August 11, 2025

@dublove it is not about the approach @brian_p_dts took but about what are the possible approaches and there are not too many in this case. You need to locate the paragraphStyle to use it and there are two collections for that on the document object, namely

  • paragraphStyles :- However, this does not contain styles that are present in the group. So you can't use this. This collection has the benefit of methods like itemByName, itemByID etc. So if you can use it this is the best method.
  • allParagraphStyles :- This contains all the paragraph styles of the document irrespective of the group in which they are present. However, this is an array, so no special methods like itemByName. Only way to find anything in this would be iterating the array. Another point to note is that styles can have the same name inside different groups. So in order to exactly find the style in a particular group you will need to check it's group as well

So the approach that @brian_p_dts used is fine, else you can also try with allParagraphStyles. However, there is no straight method to get the styles in the group.

-Manan

-Manan