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

Get Attribute Value from Structured Book

Explorer ,
Mar 20, 2017 Mar 20, 2017

Copy link to clipboard

Copied

Hello,

In a Structured book, i need to get on attribute valus (on the highest element) but ...

In a FM document, i can get value from an element by looping through all my document by "wraping" the element text and get the attributes (using : element.TextRange.beg/end).

But in a structured book, i can't wrap the "element text" because it's not text, so how can i get the value of my highest element?

TOPICS
Scripting

Views

398

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

correct answers 1 Correct answer

Advocate , Mar 20, 2017 Mar 20, 2017

Not sure what you mean by 'looping through all my document' and 'wraping the element text'. Attributes are normally not visible in the text content of a structured document. To get to the attributes, you select the element and search its attribute list for the values. You can also do this on the book, as that has structured content which works basically in the same way. The only real difference is that the book does not have flows, so you get to the highest level element in a different way:

In a

...

Votes

Translate

Translate
Advocate ,
Mar 20, 2017 Mar 20, 2017

Copy link to clipboard

Copied

Not sure what you mean by 'looping through all my document' and 'wraping the element text'. Attributes are normally not visible in the text content of a structured document. To get to the attributes, you select the element and search its attribute list for the values. You can also do this on the book, as that has structured content which works basically in the same way. The only real difference is that the book does not have flows, so you get to the highest level element in a different way:

In a structured FM document:

var oDoc = app.ActiveDoc;

var oRoot = oDoc.MainFlowInDoc,HighestLevelElement;

In a structured FM book:

var oDoc = app.ActiveBook;

var oRoot = oDoc.HighestLevelElement;

To get the attribute value for an attribute you can use this function:

function GetAttribute( oElement, sAttName ) {

     var oaAttrs = oElement.Attributes;

     var sRetVal = "";

     var i = 0;

     var bFound = false;

     while( !bFound && i < oaAttrs.length ) {

          if( oaAttrs.name == sAttName ) {

               bFound = true;

               if( oaAttrs.values.length > 0 ) {

                    sRetVal = oaAttrs.values[0];

               }

          }

          i++;

     }

     return sRetVal;

}

Good luck

4everJang

Votes

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
Explorer ,
Mar 20, 2017 Mar 20, 2017

Copy link to clipboard

Copied

LATEST

Thanks a lot for your code.

I was stuck with the attribute and making a "while function" correctly. With a clear code like your it's 10.000 times easier to understand. (I think I had my noze too long time in my code and couldn't find what was wrong).

Votes

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