Copy link to clipboard
Copied
Hi All,
I'm using the below script to replace the text frame content, but this is not working for me
var EnglishContent_array = ["A", "B", "C", "D", "E", "F", "G", "H"];
var JSON_English_content_Array = ["AA", "BB", "CC", "DD", "EE", "FF", "GG", "HH"];
var Page_Number_Array = [1, 1, 1, 1, 1, 1, 1, 1];
processTFrames();
function processTFrames() {
var doc = app.activeDocument;
var myTextFrames = doc.textFrames;
for (var i = myTextFrames.length-1; i>=0; i--) {
var textFrame = myTextFrames[i];
for (var p = textFrame.paragraphs.length-1; p >= 0; p--) {
var paragraph = textFrame.paragraphs[p];
var pageNumber = textFrame.parentPage.name;
for (var t = EnglishContent_array.length-1; t >= 0; t--) {
var englishContent = EnglishContent_array[t];
if (paragraph.contents.toLowerCase() === englishContent.toLowerCase() && pageNumber === String(Page_Number_Array[t])) {
paragraph.contents = JSON_English_content_Array[t];
break;
}
}
}
}
}
Can someone help me?
 
Thank you
AG
Copy link to clipboard
Copied
I got the output by using the below condition
var EnglishContent_array = ["A", "B", "C", "D", "E", "F", "G", "H"];
var JSON_English_content_Array = ["AA", "BB", "CC", "DD", "EE", "FF", "GG", "HH"];
var Page_Number_Array = [1, 1, 1, 1, 1, 1, 1, 1];
processTFrames();
function processTFrames() {
var doc = app.activeDocument;
var myTextFrames = doc.textFrames;
var errorFlag = false;
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences.findWhat = "^(.+)"
var results = app.activeDocument.findGrep();
//alert(result.length);
for(var r=results.length-1; r>=0; r--){
var parentpageNumber = String(results[r].parentTextFrames[0].parentPage);
var ParagraphContents = String(results[r].contents);
for(var e=EnglishContent_array.length-1; e>=0; e--){
if(String(ParagraphContents).toLowerCase() === String(EnglishContent_array[e]).toLowerCase() && parentpageNumber === parentpageNumber){
results[r].contents = String(JSON_English_content_Array[e]);
}
}
}
}
Let me know if I'm wrong.
Thanks
AG
Copy link to clipboard
Copied
*correction*
var parentpageNumber = String(results[r].parentTextFrames[0].parentPage.name)
and
if(String(ParagraphContents).toLowerCase() === String(EnglishContent_array[e]).toLowerCase() && parentpageNumber === String(Page_Number_Array[e])){
Thanks
AG
Copy link to clipboard
Copied
What is the state of the issue now? You could look at find/replace as well to accomplish what your are trying to do.
-Manan