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
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
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;
}
Copy link to clipboard
Copied
Copy link to clipboard
Copied