Skip to main content
April 12, 2024
Answered

Script: Delete Empty Style Groups

  • April 12, 2024
  • 1 reply
  • 201 views

Hello,

I would like to go through my style groups (character, paragraph, object, etc.) in order to remove empty groups and subgroups. To count the number of styles in a group, it seems that a number count() property exists, but I can't seem to put it into practice.

Does anyone have any advice on this?

This topic has been closed for replies.
Correct answer rob day

Hi @35626004 This would remove empty ParagraphStyleGroups:

 

var psg = app.activeDocument.paragraphStyleGroups.everyItem().getElements()
for (var i = 0; i < psg.length; i++){
    //count() or length works
    if (psg[i].paragraphStyles.count() == 0) {
        psg[i].remove()
    } 
}; 

1 reply

rob day
Community Expert
rob dayCommunity ExpertCorrect answer
Community Expert
April 12, 2024

Hi @35626004 This would remove empty ParagraphStyleGroups:

 

var psg = app.activeDocument.paragraphStyleGroups.everyItem().getElements()
for (var i = 0; i < psg.length; i++){
    //count() or length works
    if (psg[i].paragraphStyles.count() == 0) {
        psg[i].remove()
    } 
};