Skip to main content
Known Participant
February 8, 2024
Answered

InDesign current selection to select next paragraphs of same paragraph style comes.

  • February 8, 2024
  • 1 reply
  • 705 views

Hi All,

I've one doubt on the indesign javascript the current selection to select next paragraphs of same paragraph style or particular paragraphstyle till the selection to be adding.

there is a condtion if (title or en) paragarph style come stop the selection.

Like the below snapshot.

Input


output


like getPreviousPara() concept.
getPreviousPara() 

I tested someone code code but I can't get the solution could you anyone help me.

found  = app.selection[0];
st = found.parentStory;

pCurr = found.paragraphs[0];
ipNext = st.insertionPoints[ pCurr.insertionPoints[-1].index ];
var pNext = ipNext.paragraphs[0];

alert(pNext.contents);



Regards,
csm

This topic has been closed for replies.
Correct answer danaken3

Try this:

 

    var nextPara = app.selection[0].parentStory.paragraphs.nextItem(app.selection[0].paragraphs[-1]);

    /*Loop: If next paragraph is NOT "title" or "en" paragraph style,
    add it to the current selection. */
    try{
        while(nextPara.appliedParagraphStyle != app.activeDocument.paragraphStyles.item("title") 
        && nextPara.appliedParagraphStyle != app.activeDocument.paragraphStyles.item("en"))
        {
            nextPara.select(SelectionOptions.addTo);
            nextPara = app.selection[0].parentStory.paragraphs.nextItem(app.selection[0].paragraphs[-1]);
        }
    }
    catch(err) {
        
    }

 

1 reply

danaken3
danaken3Correct answer
Participating Frequently
February 9, 2024

Try this:

 

    var nextPara = app.selection[0].parentStory.paragraphs.nextItem(app.selection[0].paragraphs[-1]);

    /*Loop: If next paragraph is NOT "title" or "en" paragraph style,
    add it to the current selection. */
    try{
        while(nextPara.appliedParagraphStyle != app.activeDocument.paragraphStyles.item("title") 
        && nextPara.appliedParagraphStyle != app.activeDocument.paragraphStyles.item("en"))
        {
            nextPara.select(SelectionOptions.addTo);
            nextPara = app.selection[0].parentStory.paragraphs.nextItem(app.selection[0].paragraphs[-1]);
        }
    }
    catch(err) {
        
    }

 

Robert at ID-Tasker
Legend
February 9, 2024

@danaken3 

 

Why are you refering to parentTextFrames[0]? You should refer to parentStory.

 

danaken3
Participating Frequently
February 9, 2024

@Robert at ID-Tasker Updated, thanks!