Skip to main content
Known Participant
February 1, 2023
Answered

Script to apply more than paragraph style on certain range of pages Not all

  • February 1, 2023
  • 1 reply
  • 4253 views

Hi 

I have an indesign file that contain 3 different designs distrubuted along 100 pages , I have 2 paragraph styles for each design

I want a script to apply certain paragraph styles on text frames of certain pages Not All pages in the File

 

Ex : Paragraph style  (1)  from page 1 to 10 , Paragraph style (2) from page 1 to  10

       Paragraph style (3)  from page 11 to 15 , Paragraph style (4)  from page 11 to 15

 

Can I do that by a script ???

 

       

 

This topic has been closed for replies.
Correct answer FRIdNGE
/*
by FRIdNGE, Michel Allio [01/02/2023]
*/

var myDoc = app.activeDocument,
myPages = myDoc.pages;
// "O" is the first page; "4" is the 5st page.
for ( var p = 0; p < 4; p++ ) {
    var myTFrames = myPages[p].textFrames;
    // "myTFrames[1]" is the first text frame created on the page;
    // "myDoc.paragraphStyles.item("1")" is the name ("1") of the para style to be applied;
    // "myTFrames[0]" is the second text frame created on the page;
    // "myDoc.paragraphStyles.item("2")" is the name ("2") of the para style to be applied;
    myTFrames[1].paragraphs[0].appliedParagraphStyle = myDoc.paragraphStyles.item("1");
    myTFrames[0].paragraphs[0].appliedParagraphStyle = myDoc.paragraphStyles.item("2");
}
alert( "Done!…" )

… So if you want "pages 1-4", write this line:

 

for ( var p = 0; p < 4; p++ ) {
 

… if you want "pages 5-9", write this line:

 

for ( var p = 4; p < 9; p++ ) {
 

(^/)

1 reply

Known Participant
February 1, 2023

Any Help Here

Brito Haroldo
Inspiring
February 1, 2023

@r28071715i111 

In your example you went from ParagraphStyle(1) to (4). But in the post you mention applying only 2 per page. OK

So your scenario is?
a) the document has 4 different styles;
b) the application takes place in defined ranges;

I would like to think about:
i) How many text boxes are there on each page? Is it a fixed amount throughout the document?
ii) Are the texts in different TextFrames or are they a single story?
iii) The current demand pages are sequential and with a defined "step", like 5 by 5, 10 by 10 pages...
iv) it is certain that there is only one paragraph that uses the same style. I mean can it happen that two paragraphs on the page use the same style?

Can you post a screenshot of your layout or share some kind of preview of your context?

FRIdNGE
FRIdNGECorrect answer
Inspiring
February 1, 2023
/*
by FRIdNGE, Michel Allio [01/02/2023]
*/

var myDoc = app.activeDocument,
myPages = myDoc.pages;
// "O" is the first page; "4" is the 5st page.
for ( var p = 0; p < 4; p++ ) {
    var myTFrames = myPages[p].textFrames;
    // "myTFrames[1]" is the first text frame created on the page;
    // "myDoc.paragraphStyles.item("1")" is the name ("1") of the para style to be applied;
    // "myTFrames[0]" is the second text frame created on the page;
    // "myDoc.paragraphStyles.item("2")" is the name ("2") of the para style to be applied;
    myTFrames[1].paragraphs[0].appliedParagraphStyle = myDoc.paragraphStyles.item("1");
    myTFrames[0].paragraphs[0].appliedParagraphStyle = myDoc.paragraphStyles.item("2");
}
alert( "Done!…" )

… So if you want "pages 1-4", write this line:

 

for ( var p = 0; p < 4; p++ ) {
 

… if you want "pages 5-9", write this line:

 

for ( var p = 4; p < 9; p++ ) {
 

(^/)