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!
… 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
… 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
...
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.
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
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!" )
(^/)
Copy link to clipboard
Copied
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.