Skip to main content
Known Participant
June 5, 2015
Question

Running script on conditions

  • June 5, 2015
  • 1 reply
  • 583 views

I have a document with approximately 50 tables in it, some of which I need to add some text and shade some cells etc. The tables which I need to run my script over are identified by a string ( just one word ) found in the second row, first cell of these particular tables. I need to search each table in the document for this string, if the string is present then apply the script, if not present then move to the next table in the document. I've had good read around "getText" but I'm unsure if this the right way to go and still don't know how to apply it. Anybody any ideas how I could achieve this?

Thanks

Chris

This topic has been closed for replies.

1 reply

frameexpert
Community Expert
Community Expert
June 5, 2015

Here is user-defined function that will get text from any FrameMaker text object (Pgf, Cell, TextFrame, etc.) or TextRange. Please let me know if you have any questions or comments.

function getText (textObj, doc) {

    // Gets the text from the text object.

    var text = "";

    // Get a list of the strings in the text object or text range.

    if (textObj.constructor.name !== "TextRange") {

        var textItems = textObj.GetText(Constants.FTI_String);

    } else {

         var textItems = doc.GetTextForRange(textObj, Constants.FTI_String);

    }

    // Concatenate the strings.

    for (var i = 0; i < textItems.len; i += 1) {

        text += (textItems.sdata);

    }

    return text; // Return the text

}

www.frameexpert.com
Known Participant
June 15, 2015

Hi Rick, thanks for the help once again.

So the "TextRange" is the string/word that I want to find?  I don't understand the two textItems that you have put for the if else variables.


And the concatenating of the strings, please could you explain this part of what you've written?


Thanks


Chris

Known Participant
July 23, 2015

Hi Chris,

No, TextRange has nothing to do with the text you are trying to find. The function doesn't find any particular text, it just returns all of the text of a given text object (Pgf, Cell, TextLine, etc.) or TextRange (for example, a text selection). There are two separate methods for getting text items; one is for text objects (line 07) and the other for text ranges (line 09). In both cases, the methods are getting a list of strings (FTI_String) in the text object or text range. Since there could be more than on string in the object or range, lines 12-14 loop through them and concatenate them into a single string. This string gets returned on line 15.

Rick


Hi Rick,

Thanks, that's a little clearer now. In this case I would require to return text from a text object, a table cell.

How do I specify a specific cell of the currently selected table?  And when it returns the text I can then use "text" as a condition, e.g if the string "text" is equal to "XXXXX" then run the following script?

Thanks

Chris