Skip to main content
Known Participant
February 8, 2024
解決済み

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

  • February 8, 2024
  • 返信数 1.
  • 707 ビュー

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

このトピックへの返信は締め切られました。
解決に役立った回答 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

danaken3
danaken3解決!
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!