Copy link to clipboard
Copied
Hi Expert, Please Help me in Fixing this code, actually i want to change grep (AA) by (BB) as Example not only in Pages Range (0,2) but also including groups in the Pages Range and show total number changed, in pages range it was working good, but when i try to add the groups in the same ranges it gives an error, I'm Begineer in javascript so maybe my attempt is not right or need modifications, here's the script and deep thanks in advance, and Please attach explains with the fix so i will avoid mistakes in the future and learn new skills from experts, and thanks a lot again :
//Change ItemByRanges and Groups items
var PageStart = 0
var PageEnd = 2
var myDoc = app.activeDocument;
var mypages = app.activeDocument.pages;
var myFindWhat = 'AA';
var myChangeTo = "BB";
app.findGrepPreferences = NothingEnum.NOTHING;
app.changeGrepPreferences = NothingEnum.NOTHING;
app.findGrepPreferences.properties = ({ findWhat: myFindWhat });
app.changeGrepPreferences.properties = ({ changeTo: myChangeTo });
var myFoundTexts = [];
var myFoundTextParagraphs = paragraphsInPageRange.findGrep();
for (var i = 0; i < myFoundTextParagraphs.length; i++) {
for (var j = 0; j < myFoundTextParagraphs[i].length; j++) {
//Add Groups
for(var g = 0; g < myFoundTextParagraphs[j].textFrames.length; g++)
var paragraphsInPageRange = myDoc.pages.itemByRange(PageStart, PageEnd).groups[myFoundTextParagraphs[i].textFrames.parentStory].textFrames.everyItem().paragraphs.everyItem();
myFoundTexts.push(myFoundTextParagraphs[i][j][g]);
}
}
alert("Total Changed is : "+Number(myFoundTexts.length)+" GREP's","Finito");
for (var i = 0; i < myFoundTexts.length; i++) {
myFoundTexts[i][j][g].changeGrep();
}
Copy link to clipboard
Copied
Hi M. Hasanain,
could you explain a bit more?
Do you want to find text in all texts restricted to a range of pages?
( That would also include text in text frames that are grouped. )
I'd do the following:
[1] Lock all items in the document
[2] Unlock all items in the range of pages that is your scope.
[3] Run the GREP find/change
[4] Unlock all items in the document
Regards,
Uwe Laubender
( ACP )
Copy link to clipboard
Copied
Thanks a lot @Laubender for your reply, yes that what i need ,
find text in all texts restricted to a range of pages? Including text in text frames that are grouped.
I will try your method, thanks
Copy link to clipboard
Copied
I'd just run findGrep() on the doc, iterate through the finds, and compare the found text's parentTextFrames' parentPage to the desired documentOffset and execute changeGrep() and update the counter on the parentTextFrame(s). Uwe's approach may be simpler.
Copy link to clipboard
Copied
Thanks a lot @brianp311 I will consider that method also