getting text(s) of element

Community Beginner ,
Oct 09, 2019 Oct 09, 2019

Copy link to clipboard

Copied

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

TOPICS
Scripting , Structured

Views

316

Likes

Translate

Translate

Report

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
Mentor ,
Oct 09, 2019 Oct 09, 2019

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

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 Beginner ,
Oct 14, 2019 Oct 14, 2019

Copy link to clipboard

Copied

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;
     
 }

 

Likes

Translate

Translate

Report

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
Mentor ,
Oct 17, 2019 Oct 17, 2019

Copy link to clipboard

Copied

Hi, are you asking another question? If you are, I do not know what the question is.

Likes

Translate

Translate

Report

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 Beginner ,
Oct 17, 2019 Oct 17, 2019

Copy link to clipboard

Copied

LATEST
it wasn't a question but just how i manage the HLE in my script.

Likes

Translate

Translate

Report

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