Skip to main content
andranika45761163
Known Participant
October 9, 2019
Question

getting text(s) of element

  • October 9, 2019
  • 2 replies
  • 571 views

Hi,

 

does anybody know how can I get the text(s - for nested element ) of framemaker elements.

 

example

var doc = app.ActiveDoc
var root = doc.MainFlowInDoc.HighestLevelElement

 

how to get the text of the root ?

 

thanks

This topic has been closed for replies.

2 replies

Participating Frequently
October 14, 2019

Hello

On my side i have got this  function when i work with the HLE (hightest level element)

doc = app.ActiveDoc;
var root=GetFirstElement(doc);
tag = root.ElementDef.Name;
          $.writeln(" HLE="+tag);
           if (tag=="ABC"){      
              // Do something;
              alert ("test ok");
              }

function GetFirstElement(doc) {
     var doc, flow, root,tag,attrs;
     
    //doc = app.ActiveDoc;
    flow = doc.MainFlowInDoc;
    root = flow.HighestLevelElement;
    
    return root;
     
 }

 

Legend
October 17, 2019
Hi, are you asking another question? If you are, I do not know what the question is.
Participating Frequently
October 17, 2019
it wasn't a question but just how i manage the HLE in my script.
Legend
October 9, 2019

Hi andranika,

 

Here is a function I use to get the text of an element. It only works for container and table cell elements, not markers, xrefs, etc. Hope this helps.

 

   
        
//if you want to preserve pgf marks with some sort of character (\n, etc.)
//send it for pgfMarkSubstitution, otherwise send an empty string.
function elem_GetElementText(doc, elem, pgfMarkSubstitution)
{
    var text = "";
    
    if(!doc.ObjectValid()) doc = app.ActiveDoc;
    if(!doc.ObjectValid()) return "";
    
    if(!elem.ObjectValid()) return "";
    
    var tr = new TextRange();
    
    if(elem.ElementType == Constants.FV_FO_TBL_CELL)
    {
        tr.beg.obj = elem.Object.FirstPgf;
        tr.beg.offset = 0;
        tr.end.obj = elem.Object.FirstPgf;
        tr.end.offset = Constants.FV_OBJ_END_OFFSET;
    }
        
    else tr = elem.TextRange;
    
    //doc.TextSelection = tr;
    //return "";
    
    var ti = doc.GetTextForRange(tr, Constants.FTI_String | Constants.FTI_PgfEnd);
    
    for(var i = 0; i < ti.len; i++)
    {
        if(ti[i].dataType == Constants.FTI_PgfEnd && pgfMarkSubstitution != "")
            text += pgfMarkSubstitution;
        else if(ti[i].dataType == Constants.FTI_String)
            text += ti[i].sdata;
    }

    return text;    
}

 

Russ