Skip to main content
Known Participant
April 24, 2019
Answered

FM 2019: Find and Replace Text Inside of Marker

  • April 24, 2019
  • 2 replies
  • 1460 views

Hello -- I have a giant publication that contains hundreds of hypertext markers that contain codes that change yearly. FM can find based on the code, but the change option pastes the new code into the body instead of at the end of the hyperlink as it should.

I can make the change after exporting to html5, but isn't there a way I can efficiently do it in the source files?

Thanks in advance ...

Mike

    This topic has been closed for replies.
    Correct answer Russ Ward

    This is fantastic Russ, thanks! I do confess that I'm unfamilar with extendscript, but can work with java, which it looks identical to. Can you please let me know where I execute this from or point me to a good tutorial?

    Much obliged! 

    -Mike


    Hi Mike,

    You can find lots of samples for beginners here:

    FrameMaker ExtendScript Samples - West Street Consulting

    To answer your immediate question, you should be able to just:

    1 - Select File > Script > New Script.

    2 - In the ExtendScript toolkit editor, you should get a blank script file. Paste the script I gave you into that file.

    3 - Because the code I gave you is encapsulated in a function, you'll need to add the following line to the beginning of the file to execute it:

    searchAndReplaceMarkerText();

    4 - Make sure the desired file is open in FrameMaker and click the Run button in the editor.

    Note that you need to have FM2019 fully updated for this to work. There was a bug in the initial release version where the File > Script > New Script command did nothing.

    Hope this gets you somewhere.

    Russ

    2 replies

    LinSims
    Community Expert
    Community Expert
    April 24, 2019

    As another thought, you MIGHT be able to do this by saving the files out to MIF, editing the link in the MIF, and then converting back to Frame.

    LinSims
    Community Expert
    Community Expert
    April 24, 2019

    To the best of my knowledge, FrameMaker does not provide S&R capabilities within any of the various markers. However, you might want to get in touch with Silicon Prairie Software. The IndexTools Pro plugin is used to create index markers based on text included in a document that has a special format and condition; it can also expand existing Index markers into that text. It might be adaptable to hypertext markers, and Steve does do custom work. I don't know what his rates are, though.

    Community Expert
    April 25, 2019

    Hi,

    Yes, good tip.

    Silicon Prairie`s Index Tools Pro plugin inserts the marker text as regular text. Therefore you can work with variables, search and replace text and apply conditions.

    You can test the plugins before you buy.

    https://www.siliconprairiesoftware.com/Products.html

    Best regards

    Winfried

    Known Participant
    April 25, 2019

    Hi Mike,

    This is a perfect job for ExtendScript. And it would not require much code. The following simple script function will search all markers in the active document and replace the FindMe value with the ReplaceMe value. It is case-sensitive but it doesn't need to be.

    function searchAndReplaceMarkerText()

    {

        var searchString = "FindMe";

        var replaceString = "ReplaceMe";

        var markersAdjusted = 0;

       

        var doc = app.ActiveDoc;

        if(!doc.ObjectValid())

        {

            alert("No active document. Cannot continue");

            return;

        }

        var marker = doc.FirstMarkerInDoc;

        while(marker.ObjectValid())

        {

            var text = marker.MarkerText;

            var index = text.indexOf(searchString);

            if(index > -1)

            {

                text = text.substring(0, index) +

                    replaceString +

                    text.substring(index + searchString.length, text.length);

                   

                marker.MarkerText = text;

                markersAdjusted++;

            }

           

            marker = marker.NextMarkerInDoc;       

         }

        alert("Operation complete. " + markersAdjusted + " markers adjusted.");

    }

    Hope this helps.

    Russ


    This is fantastic Russ, thanks! I do confess that I'm unfamilar with extendscript, but can work with java, which it looks identical to. Can you please let me know where I execute this from or point me to a good tutorial?

    Much obliged! 

    -Mike