Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
13

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

Explorer ,
Feb 08, 2024 Feb 08, 2024

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
Screenshot 2024-02-09 at 12.40.18 AM.png

output
Screenshot 2024-02-09 at 12.50.26 AM.png

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

TOPICS
Scripting , SDK
417
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Participant , Feb 09, 2024 Feb 09, 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);
            nex
...
Translate
Participant ,
Feb 09, 2024 Feb 09, 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) {
        
    }

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 09, 2024 Feb 09, 2024

@danaken3 

 

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

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 09, 2024 Feb 09, 2024

@Robert at ID-Tasker Updated, thanks!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 09, 2024 Feb 09, 2024

@danaken3  works perfect!

But I seen one post in same ID Scirpting forum if we used the nextItem() the performance getting slow, in more stories and more pages.

Thank for your support!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 10, 2024 Feb 10, 2024
LATEST

@suntech

 

Unfortunately, that's the price you've to pay for using next/prev.

 

Do you need to do it once - globally - or many times - selectively? 

On the same Story - multiple Stories?

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines