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

How to replace content in textframe

Explorer ,
Jun 07, 2023 Jun 07, 2023

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?

Screenshot 2023-06-07 at 8.15.10 PM.png

 


Thank you
AG

TOPICS
Scripting

Views

171

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 ,
Jun 07, 2023 Jun 07, 2023

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

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 ,
Jun 07, 2023 Jun 07, 2023

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

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
Community Expert ,
Jun 07, 2023 Jun 07, 2023

Copy link to clipboard

Copied

LATEST

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

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