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

Find and Replace OLD paragraph text with the NEW Text

Engaged ,
May 30, 2018 May 30, 2018

Copy link to clipboard

Copied

Hello!

I have 2 indesign files called TextNEW (without paragraph styles) and TextOLD. Both documents have exactly same number of paragraph. And I would like a script to find and replace the old text paragraph for the new text. Keep in mind, not all paragraph have changes. Please see the example, the text color RED show you the changes to apply in the TextOLD file. Like you can see the text of the Article 2 is empty in this case, and of course, the text from the TextNEW need be copied into the empty paragraph of the TextOLD.:

TextNEW:

Article 1.

All human beings are born free and equal in dignity and rights. They are endowed with reason and conscience and should act towards one another in a spirit of brotherhood.

Article 2.

Everyone is entitled to all the rights and freedoms.

Article 3.

Everyone has the right to life, liberty and security of person.

TextOLD:

Article 1.

All persons beings are born free and equal in dignity and rights. They are endowed with reason and conscience and should act towards one another in a spirit of brotherhood.

Article 2.

Article 3.

Everyone has the right to life, liberty and security of person.

AFTER RUN THE SCRIPT THE TextOLD file:

Article 1.

All human beings are born free and equal in dignity and rights. They are endowed with reason and conscience and should act towards one another in a spirit of brotherhood.

Article 2.

Everyone is entitled to all the rights and freedoms.

Article 3.

Everyone has the right to life, liberty and security of person.

Like you can see my TextNEW have NOT paragraph styles applied:

Screen Shot 2018-05-30 at 17.40.39.png

my TextOLD have paragraph styles applied:

Screen Shot 2018-05-30 at 17.41.59.png

here you can Download the files here.

Thanks so much!

TOPICS
Scripting

Views

463

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

correct answers 1 Correct answer

Engaged , Jun 13, 2018 Jun 13, 2018

Hi,

here the solution:

Download the files and InDesign example

THE SCRIPT

try{

var myNewStory = app.activeDocument.stories[0];

} catch(myError){ alert("myNewStory not found. Document is empty?"); exit();}

try{

var myOldStory = app.documents[1].stories[0];

} catch(myError){ alert("myOldStory not found. Document is empty?"); exit();}

var myNewParagraphs = myNewStory.paragraphs;

var NewLen = myNewParagraphs.length;

var myOldParagraphs = myOldStory.paragraphs;

var OldLen = myNewParagraphs.length;

if(OldLen !=NewL

...

Votes

Translate

Translate
Engaged ,
Jun 13, 2018 Jun 13, 2018

Copy link to clipboard

Copied

LATEST

Hi,

here the solution:

Download the files and InDesign example

THE SCRIPT

try{

var myNewStory = app.activeDocument.stories[0];

} catch(myError){ alert("myNewStory not found. Document is empty?"); exit();}

try{

var myOldStory = app.documents[1].stories[0];

} catch(myError){ alert("myOldStory not found. Document is empty?"); exit();}

var myNewParagraphs = myNewStory.paragraphs;

var NewLen = myNewParagraphs.length;

var myOldParagraphs = myOldStory.paragraphs;

var OldLen = myNewParagraphs.length;

if(OldLen !=NewLen) {alert("There is a mismatch between the number of paragraphs"); exit(); }

var myParaStyles = [], myStyle, myText;

if(myNewParagraphs.item(0).parentStory.insertionPoints.item(-1).index == myNewParagraphs.item(-1).insertionPoints.item(-1).index){

myNewParagraphs.item(-1).insertionPoints.item(-1).contents = "\r";

}

   

if(myOldParagraphs.item(0).parentStory.insertionPoints.item(-1).index == myOldParagraphs.item(-1).insertionPoints.item(-1).index){

myOldParagraphs.item(-1).insertionPoints.item(-1).contents = "\r";

}

for(var i=0; i<NewLen; i++) {

myParaStyles.push(myOldStory.paragraphs.appliedParagraphStyle);

}

for(var i=0; i<NewLen; i++) {

myOldStory.paragraphs.contents = "\r";

myText = myNewParagraphs.characters.itemByRange(0, myNewParagraphs.characters.length-2);

myText.duplicate(LocationOptions.atBeginning, myOldStory.paragraphs.insertionPoints.item(0) );

}

for(var i=0; i<NewLen; i++) {

myOldStory.paragraphs.appliedParagraphStyle = myParaStyles;

}

QUICK VIEW

01.png

02.png

03.png

04.png

05.png

06.png

07.png

Thanks, Boris for your help.

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