Skip to main content
Participant
August 7, 2014
Answered

Finding and replacing Paragraph Style of last line in a bulletted list?

  • August 7, 2014
  • 1 reply
  • 5236 views

Hi,

I'm wondering if there's a way (or a script out there) to automate finding the last item of a bulletted list and apply a paragraph style? I'm dealing with multiple, hundred-page documents with tons of bulletted lists, and currently I'm applying a paragraph style to each of these in order to increase the space below the list and the top of the next paragraph.

Suggestions?

This topic has been closed for replies.
Correct answer Kai Rübsamen

It’s not clear to me, if the bullets are formatted at this time or how you indentify them.

But try the following:

app.findGrepPreferences = app.changeGrepPreferences = null; 

app.findGrepPreferences.properties = { bulletsAndNumberingListType: ListType.BULLET_LIST };

var allFounds = app.findGrep();

for ( var i = 0; i < allFounds.length; i++ ) {

    var curFound = allFounds;

    var allParas = curFound.paragraphs;

    var nParas = allParas.length;

    allParas[nParas-1].appliedParagraphStyle = "bulletLast";

}

app.findGrepPreferences = app.changeGrepPreferences = null; 

–Kai

1 reply

Kai Rübsamen
Kai RübsamenCorrect answer
Participating Frequently
August 7, 2014

It’s not clear to me, if the bullets are formatted at this time or how you indentify them.

But try the following:

app.findGrepPreferences = app.changeGrepPreferences = null; 

app.findGrepPreferences.properties = { bulletsAndNumberingListType: ListType.BULLET_LIST };

var allFounds = app.findGrep();

for ( var i = 0; i < allFounds.length; i++ ) {

    var curFound = allFounds;

    var allParas = curFound.paragraphs;

    var nParas = allParas.length;

    allParas[nParas-1].appliedParagraphStyle = "bulletLast";

}

app.findGrepPreferences = app.changeGrepPreferences = null; 

–Kai

Obi-wan Kenobi
Legend
August 7, 2014

Hi Kai,

I do it with a little grep search. 

Kai Rübsamen
Participating Frequently
August 18, 2014

Kai,

Don't be sorry! The script works very fine in the way you've written it.

It doesn't work in another case where I find interesting to make it work. That's what I show in my sample:

I have a group of paras styled with "Style 0" and I want to apply: Style 1 to the first para, Style 2 to the following and Style 3 to the last.

Here, I don't use (auto-numbering or manual) bullets.

So, I think "bullets" should not be an essential criterion for research.

For me, the good way is:

Search a paras group (in sequence) with the same style (no manual bullet used but possibly auto-numbering)

or

Search a paras group (in sequence) with the same manual bullet

or

Search a paras group (in sequence) with the same style and the same manual bullet.


My problem is, that I don’t know at the moment how single paragraphs with manual bullets can be treated at one list. This is easier, if there is already a list. You can check this, if you search for style 0 (all paragraphs are highlighted) or if you search with e.g. '•\t.+\r' (only one paragraph is highlighted).

edit: Ah, maybe '(•\t.+\r)+' this will work ;-)

In the meantime. Something like that for your first need?

// Enter your style names

//

var paraStyle_0 = "style 0",

    paraStyle_1 = "style 1",

    paraStyle_2 = "style 2";

    paraStyle_3 = "style 3";

app.findGrepPreferences = app.changeGrepPreferences = null;    

app.findGrepPreferences.properties = { appliedParagraphStyle: paraStyle_0 };   

var allFounds = app.findGrep();  

    

for ( var i = 0; i < allFounds.length; i++ ) {  

        var curFound = allFounds;  

        var allParas = curFound.paragraphs;

        // whole list

        allParas.everyItem().appliedParagraphStyle = paraStyle_2;

        // first bullet

        allParas[0].appliedParagraphStyle = paraStyle_1;

        // last bullet

        allParas[allParas.length-1].appliedParagraphStyle = paraStyle_3;  

}  

    

app.findGrepPreferences = app.changeGrepPreferences = null;