• 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 text

Contributor ,
Feb 21, 2024 Feb 21, 2024

Copy link to clipboard

Copied

This should be a simple and common question, but most posts I found linked back to this:

https://community.adobe.com/t5/framemaker-discussions/find-replace/td-p/3581679#4032650

 

I tried the script there and failed.  Some things that would help hopefully:

 

I'm trying to replace one name at the end of a document in the main flow (in the last table of the document). So the script only has to start at the end and when it makes the first replacement or leaves the table, it is done.

 

From the linked thread, I tried to use (obfuscating a bit):

FindAndReplaceString(app.activeDoc,app.activeDoc.MainFlowInDoc,'CHARLES T . SMITH','JOHN Q. PUBLIC', 'True');

And I got "Undefined is not an object"

 

Second question. Currently this name is in plain text in our FM template.

I'm considering putting it in a user variable - maybe named _Signature.

Would the script still find and replace it if I did this?

Or - 

I have a script which updates the document with the latest Master Page Formats, but it's been a while since I've looked at it. I have these lines in the script:

doc.SimpleImportFormats (New_Template, formatFlags);

 

function FixCopyrightDate(doc)
{
var variable;
variable = doc.GetNamedVarFmt ("Current Date (Long)");
variable.Fmt = "<$year>";
}// -- End Fix CopyrightDate

 

Could either of these be (easily) modifed to update ONLY _Signature without updated ALL the other user variables as well?

 

I could test the last two items, but the experts on here probably know instantly and I still need the solution to the initial question.

 

Disregard the strike-thru text - I'm pretty sure I can update the user variables.

 

Let me know if anything is unclear.

 

Thanks in advance!!!

TOPICS
Scripting

Views

227

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

Contributor , Feb 22, 2024 Feb 22, 2024

@frameexpert - Thank you and I appreciate the offer. I know from experience on this forum that your code is top-notch and I'll check with my manager about purchasing your script.

 

For now, I re-read CAREFULLY the linked thread and I was able to get Ian's script to work. I had two errors - first, the value for ConsiderCase should be 1, not 'True'. Second, my VBA background was showing through and came back to bite me.
Once I copied his function, you run it like this:

var activeDoc = app.ActiveDoc;
v
...

Votes

Translate

Translate
Community Expert ,
Feb 21, 2024 Feb 21, 2024

Copy link to clipboard

Copied

Hi Marshall, If you have budget, you might try my FindChangeBatch script at www.frameexpert.com/store. If you can afford the source code version, it will give you a lot of code that you can learn from and use in your own scripts. I can try to post some code here, but a find/change script requires a lot of code to do all of its tasks.

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
Contributor ,
Feb 22, 2024 Feb 22, 2024

Copy link to clipboard

Copied

@frameexpert - Thank you and I appreciate the offer. I know from experience on this forum that your code is top-notch and I'll check with my manager about purchasing your script.

 

For now, I re-read CAREFULLY the linked thread and I was able to get Ian's script to work. I had two errors - first, the value for ConsiderCase should be 1, not 'True'. Second, my VBA background was showing through and came back to bite me.
Once I copied his function, you run it like this:

var activeDoc = app.ActiveDoc;
var flow = activeDoc.MainFlowInDoc;
var findString = 'CHARLES T. SMITH';
var replaceString = 'JOHN Q. PUBLIC';
// 0 = No, 1 = Yes for Consider Case.
var considerCase = 1;
FindAndReplaceString(activeDoc, flow, findString, replaceString, considerCase) 

This (corrected) won't work, although it seems more compact and seems like it SHOULD work:

FindAndReplaceString(app.activeDoc,app.activeDoc.MainFlowInDoc,'CHARLES T. SMITH','JOHN Q. PUBLIC', 1);

This (corrected):

FindAndReplaceString('app.activeDoc','app.activeDoc.MainFlowInDoc','CHARLES T. SMITH','JOHN Q. PUBLIC', '1');

Gets to the called function, but then gives an error of "ActiveDoc.ObjectValid is not a function."

 

Thank you again for all the assistance and hopefully this helps others!!!

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 ,
Feb 23, 2024 Feb 23, 2024

Copy link to clipboard

Copied

LATEST

I forgot that I have a YouTube playlist on doing Find/Change with ExtendScript!

https://youtube.com/playlist?list=PLRPNZaAC4LoTosB8ClbFbFn2ijROFJUlJ&si=A7Rfk1zlRBb3bq4H

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