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

Find 2-line paragraphs with a certain style and change the style

Explorer ,
Jul 03, 2023 Jul 03, 2023

Copy link to clipboard

Copied

Hello,

I'm typesetting a workbook that has questions with lines to write the answers. Most of the questions are a single line, but some are two lines. All are set with the same paragraph style. I need to change all the two-line questions to a different paragraph style and I'm wondering if there's an automated way to do that.

Thanks!

TOPICS
How to , Scripting , Type

Views

188

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 2 Correct answers

Guide , Jul 03, 2023 Jul 03, 2023

… Hmm!

 

Of course, it could be done by a simplistic script but let's try to do it with … Grep [for those who know it]!

 

Supposing we have 2 para styles: "xxx" and "yyy".

 

First, add 2 nested lines styles to your para style "xxx":

First line: [none]

Second line: "zzz" char style (no attribute)

 

… And just play this simplistic Grep Find/Replace:

 

Find: $ + "zzz" char style

Replace by: "yyy" para style

 

Funny: 0 result, but it makes the job!

 

(^/)  The Jedi

Votes

Translate

Translate
Guide , Jul 03, 2023 Jul 03, 2023

… by Script:

 

var myDoc = app.activeDocument;

var myParaStyle1 = myDoc.paragraphStyles.item("xxx");
var myParaStyle2 = myDoc.paragraphStyles.item("yyy");

app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences.findWhat = ".+";
app.findGrepPreferences.appliedParagraphStyle = myParaStyle1;  
myFound = myDoc.findGrep();
var F = myFound.length,  f;
for ( f = 0; f < F ; f++ ) if ( myFound[f].lines.length == 2 ) myFound[f].appliedParagraphStyle = myParaStyle2;
app.findGrep
...

Votes

Translate

Translate
Community Expert ,
Jul 03, 2023 Jul 03, 2023

Copy link to clipboard

Copied

No doubt it will require a script because it's not built-in to InDesign. If you're lucky, someone may have created one or could write one.

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
Guide ,
Jul 03, 2023 Jul 03, 2023

Copy link to clipboard

Copied

… Hmm!

 

Of course, it could be done by a simplistic script but let's try to do it with … Grep [for those who know it]!

 

Supposing we have 2 para styles: "xxx" and "yyy".

 

First, add 2 nested lines styles to your para style "xxx":

First line: [none]

Second line: "zzz" char style (no attribute)

 

… And just play this simplistic Grep Find/Replace:

 

Find: $ + "zzz" char style

Replace by: "yyy" para style

 

Funny: 0 result, but it makes the job!

 

(^/)  The Jedi

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
Guide ,
Jul 03, 2023 Jul 03, 2023

Copy link to clipboard

Copied

… by Script:

 

var myDoc = app.activeDocument;

var myParaStyle1 = myDoc.paragraphStyles.item("xxx");
var myParaStyle2 = myDoc.paragraphStyles.item("yyy");

app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences.findWhat = ".+";
app.findGrepPreferences.appliedParagraphStyle = myParaStyle1;  
myFound = myDoc.findGrep();
var F = myFound.length,  f;
for ( f = 0; f < F ; f++ ) if ( myFound[f].lines.length == 2 ) myFound[f].appliedParagraphStyle = myParaStyle2;
app.findGrepPreferences = app.changeGrepPreferences = null;

alert( "Done!" )

 

(^/)

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
Explorer ,
Jul 05, 2023 Jul 05, 2023

Copy link to clipboard

Copied

LATEST

I love the clever, non-script answer! I thought there might be a solution using grep but hadn't landed on that idea. Thanks also for the script. I'll see which solution seems simpler/faster to implement with my doc.

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