Copy link to clipboard
Copied
var myDoc = app.activeDoucment;
var myFrame1 = myDoc.textFrames.itemByName("one");
var myFrame2 = myDoc.textFrames.itemByName("two");
var myFrame1 = myDoc.textFrames.itemByName("three"); //and so on
var myFrames = [myFrame1, myFrame2, myFrame3] // and so on
for (var i=0; i< myFrames.length; i++)
{
var myText = myFrames[i].parentStory.contents;
myText = myText.replace(/\r\r/g, "\r"); // double enter to single enter
myFrames[i].parentStory.contents = myText;
}
This is working fine but if any two consective paragraphs has bold format in the starting then after find-replace formatting got mixed. The concern is not to mix formatting of paragaphs.
In what way does it not work? Error message?
Anyway, this example works for me:
var myDoc = app.activeDoucment;
var myFrame1 = myDoc.textFrames.itemByName("one");
var myFrame2 = myDoc.textFrames.itemByName("two");
var myFrame3 = myDoc.textFrames.itemByName("three"); //and so on
var myFrames = [myFrame1, myFrame2, myFrame3] // and so on
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences.findWhat = '\\r\\r+';
app.changeGrepPreferences.changeTo = '\\r';
for
...
Copy link to clipboard
Copied
Change myFrames[i].parentStory.contents to myFrames[i].contents
Copy link to clipboard
Copied
hi Peter, many thanks for the swift reply but formatting got merged. I also tried usual findreplace (findWhat etc) but not sure how to apply only in required text frames instead of whole document.
Copy link to clipboard
Copied
> formatting got merged
I was guessing that you were working on a text-only document 🙂
You can use InDesign's findWhat and changeTo. use
// Set up the findWhat and changeTo, then
myFrames[i].texts[0].changeGrep();
Copy link to clipboard
Copied
hi again Peter, I used in a loop but it did not work. any direct help is helpful.
Copy link to clipboard
Copied
In what way does it not work? Error message?
Anyway, this example works for me:
var myDoc = app.activeDoucment;
var myFrame1 = myDoc.textFrames.itemByName("one");
var myFrame2 = myDoc.textFrames.itemByName("two");
var myFrame3 = myDoc.textFrames.itemByName("three"); //and so on
var myFrames = [myFrame1, myFrame2, myFrame3] // and so on
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences.findWhat = '\\r\\r+';
app.changeGrepPreferences.changeTo = '\\r';
for (var i = myFrames.length-1; i >= 0; i--) {
myFrames[i].texts[0].changeGrep()
}
Copy link to clipboard
Copied
Hi Peter again,
Thank you. The error could be becuase of:
1) I kept findwhat and changeTo inside for loop
2) for loop start with i =0 and increasing
Regards
Virender