Skip to main content
Sings
Participating Frequently
February 10, 2021
Answered

I want to find and replace strings in Framemaker's Extendscript (jsx).

  • February 10, 2021
  • 3 replies
  • 1763 views

I want to find and replace strings in Framemaker's Extendscript (jsx).

- Searches for a specific string with a regular expression and replaces the string.
- Find specific text and apply a paragraph style to the paragraphs that contain the text.

Framemaker's Extendscript has so little information that it is completely unknown.
Please tell me who is kind.

    This topic has been closed for replies.
    Correct answer frameexpert

    Here is a way to try it with the paragraph containing your cursor.

    #target framemaker
    
    var doc, pgf;
    
    doc = app.ActiveDoc;
    if (doc.ObjectValid () === 1) {
        // Get the paragraph that has the text cursor.
        pgf = doc.TextSelection.beg.obj;
        // Call the function to apply the Title paragraph format.
        applyPgfFmt (pgf, "Title", doc);
    }

    3 replies

    frameexpert
    Community Expert
    Community Expert
    February 11, 2021

    Here is a function that I use to apply a paragraph format to a paragraph. You need a Pgf object (pgf), the name of the paragraph format as a string (name), and the Doc object (doc).

    function applyPgfFmt (pgf, name, doc) {
        
        var pgfFmt, props;
        
        pgfFmt = doc.GetNamedPgfFmt (name);
        if (pgfFmt.ObjectValid ()) {
            props = pgfFmt.GetProps ();
            pgf.SetProps(props);
        }
        else {
            pgf.Name = name;
         }
    }
    
    frameexpert
    Community Expert
    frameexpertCommunity ExpertCorrect answer
    Community Expert
    February 11, 2021

    Here is a way to try it with the paragraph containing your cursor.

    #target framemaker
    
    var doc, pgf;
    
    doc = app.ActiveDoc;
    if (doc.ObjectValid () === 1) {
        // Get the paragraph that has the text cursor.
        pgf = doc.TextSelection.beg.obj;
        // Call the function to apply the Title paragraph format.
        applyPgfFmt (pgf, "Title", doc);
    }
    Sings
    SingsAuthor
    Participating Frequently
    February 11, 2021

    Hi frameexpert

     

    Thanks for your reply.
    The method you told me worked correctly.

    There is one more problem that I couldn't solve.
    I don't know how to specify regular expression options when searching.
    The following post is a guide to running the find/replace script.

     

    https://community.adobe.com/t5/framemaker/find-replace/m-p/3581679

     

    I looked at other regular expression-related posts and tried to fix them, but they didn't work correctly.
    I don't know how to specify "Constants.FF _ FIND _ USE _ REGEX".
    How do I specify regular expression options?

    Klaus Göbel
    Legend
    February 10, 2021

    So try it step by step. If you have problems with any step, just come back and we will help you.

    Sings
    SingsAuthor
    Participating Frequently
    February 11, 2021

    Assign the style name to "replaceObject".
    If I set "replaceObject" below, I could change the style just in case.

    ------------------------------------------------
    activeDoc.TextSelection.beg.obj.Name
    activeDoc.TextSelection.end.Name
    ------------------------------------------------

    However, only the name of the paragraph style has changed, so I need to re-import the correct paragraph style from another file.
    It took time to process.
    Just in case, I was able to change the paragraph style in Search.

    Sings
    SingsAuthor
    Participating Frequently
    February 11, 2021

    >activeDoc.TextSelection.end.Name

    There was one mistake.
    The correct way is as follows.
    ------------------------------------------------
    activeDoc.TextSelection.end.object.Name
    ------------------------------------------------

    Klaus Göbel
    Legend
    February 10, 2021

    The first thing you should do is to search here in the forum.

    There are lots of posts concerning that issue.

     

    Search string: "find() replace"

    Sings
    SingsAuthor
    Participating Frequently
    February 10, 2021

    Thank you for taking the time to reply.
    I appreciate your kindness.

    >- Searches for a specific string with a regular expression and replaces the string.
    Thanks to you, this is solved.
    It's a lot more complicated than doing the same thing with Indesign.

    >- Find specific text and apply a paragraph style to the paragraphs that contain the text.
    This looks difficult.
    I have no idea.