Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

FrameMaker - ExtendScript Writing text to console

New Here ,
Jan 16, 2025 Jan 16, 2025

Hello 

I am trying to create an ExtendScript that takes contents from a FrameMaker document and write it to the Console in the first instance:

This is my attempt:

var doc = app.ActiveDoc;
var firstPgf = doc.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf;floop(firstPgf);

function floop(Pgf){
while(Pgf){
var pgfText = Pgf.GetText(Constants.FTI_String);
Pgf=doc.MainFlowInDoc.FirstTextFrameInFlow.NextPgf;
for(var i=0; i<pgfText.length;i++){
$.writeln(pgfText[i]);
}
$.writeln(pgfText);
}
}

------

The output I get is:

[object TextItem]
Result: undefined
[object TextItem]
[object TextItem]
[object TextItem]
[object TextItem]
[object TextItem]
[object TextItem],[object TextItem],[object TextItem],[object TextItem],[object TextItem]
Result: undefined

The object instances returned seem to be empty or not read at all.

Can you advise?

Thanks

 

424
Translate
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

Community Expert , Jan 16, 2025 Jan 16, 2025

There are some other problems with your code. Here is what you can use for a shell; add the getText function to the bottom of this script:

#target framemaker

main ();

function main () {
    
    var doc;
    
    doc = app.ActiveDoc;
    if (doc.ObjectValid () === 1) {
        processDoc (doc);
    }
}

function processDoc (doc) {
    
    var pgf;
    
    pgf = doc.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf;
    while (pgf.ObjectValid () === 1) {
        Console (getText (pgf, doc));
      
...
Translate
Community Expert ,
Jan 16, 2025 Jan 16, 2025

TextItems can be a little complicated to figure out because you have to know what properties to extract. Here is a function that you call for each paragraph that will give you the paragraph's text:

function getText (textObj, doc) {
    
    // Gets the text from the text object or text range.

    var textItems, text, 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 = "";
    for (i = 0; i < textItems.len; i += 1) {
        text += (textItems[i].sdata);
    }
    
    return text; // Return the text
}
Translate
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 ,
Jan 16, 2025 Jan 16, 2025

There are some other problems with your code. Here is what you can use for a shell; add the getText function to the bottom of this script:

#target framemaker

main ();

function main () {
    
    var doc;
    
    doc = app.ActiveDoc;
    if (doc.ObjectValid () === 1) {
        processDoc (doc);
    }
}

function processDoc (doc) {
    
    var pgf;
    
    pgf = doc.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf;
    while (pgf.ObjectValid () === 1) {
        Console (getText (pgf, doc));
        pgf = pgf.NextPgfInFlow;
    }
}
Translate
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
New Here ,
Jan 17, 2025 Jan 17, 2025
LATEST

Thanks very much. It works.

Translate
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