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

Try to Apply Paragraph Style for Even and Odd Paragraphs

Enthusiast ,
Sep 10, 2022 Sep 10, 2022

Copy link to clipboard

Copied

Hi Experts,

im trying to apply Paragraph Style1 for the first paragraph then apply Paragraph Style2 for the next and loop that in the selected frame, but it only apply to first one and stopped!, here is the code and thanks in advance :

var myFrame = app.selection[0].paragraphs[0];
 
 for (i=0; i < myFrame.paragraphs.length; i++){
        if (i % 2 == 0){
        myFrame.parentStory.paragraphs[i].appliedParagraphStyle = app.activeDocument.paragraphStyles.item("Style1");
       }
        else if (i % 2 !== 0){
        myFrame.parentStory.paragraphs[i].appliedParagraphStyle = app.activeDocument.paragraphStyles.item("Style2");
       }    
}

 

Best
Mohammad Hasanin
TOPICS
Scripting

Views

94

Translate

Translate

Report

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

Community Expert , Sep 10, 2022 Sep 10, 2022

The first line should be

var myFrame = app.selection[0];

You are running the loop on the first paragraph object and hence the loop executes just once.

-Manan

Votes

Translate

Translate
Community Expert ,
Sep 10, 2022 Sep 10, 2022

Copy link to clipboard

Copied

The first line should be

var myFrame = app.selection[0];

You are running the loop on the first paragraph object and hence the loop executes just once.

-Manan

Votes

Translate

Translate

Report

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
Enthusiast ,
Sep 10, 2022 Sep 10, 2022

Copy link to clipboard

Copied

LATEST

Thanks @Manan Joshi , i forget about that, thanks a lot

Best
Mohammad Hasanin

Votes

Translate

Translate

Report

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