Skip to main content
frameexpert
Community Expert
Community Expert
March 15, 2024
Answered

Get FrameMaker Text as a String

  • March 15, 2024
  • 1 reply
  • 370 views

How do I get FrameMaker text into a string using ExtendScript?

This topic has been closed for replies.
Correct answer frameexpert
#target framemaker

var doc, textRange, text;

// Make variables for the active document and the current text selection.
doc = app.ActiveDoc;
textRange = doc.TextSelection; // TextRange object

text = getText (textRange, doc);
alert (text);

function getText (textObj, doc) {

    // Gets the text from the text object.

    var textItems, text, count, i;
    
    // Get a list of the strings in the text object or text range.
    if (textObj.constructor.name !== "TextRange") {
        textItems = textObj.GetText (Constants.FTI_String);
    } 
    else {
         textItems = doc.GetTextForRange (textObj, Constants.FTI_String);
    }
    
    // Concatenate the strings.
    text = "";
    count = textItems.length;
    for (i = 0; i < count; i += 1) {
        text += (textItems[i].sdata);
    }
    
    return text;
}

1 reply

frameexpert
Community Expert
frameexpertCommunity ExpertAuthorCorrect answer
Community Expert
March 15, 2024
#target framemaker

var doc, textRange, text;

// Make variables for the active document and the current text selection.
doc = app.ActiveDoc;
textRange = doc.TextSelection; // TextRange object

text = getText (textRange, doc);
alert (text);

function getText (textObj, doc) {

    // Gets the text from the text object.

    var textItems, text, count, i;
    
    // Get a list of the strings in the text object or text range.
    if (textObj.constructor.name !== "TextRange") {
        textItems = textObj.GetText (Constants.FTI_String);
    } 
    else {
         textItems = doc.GetTextForRange (textObj, Constants.FTI_String);
    }
    
    // Concatenate the strings.
    text = "";
    count = textItems.length;
    for (i = 0; i < count; i += 1) {
        text += (textItems[i].sdata);
    }
    
    return text;
}