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

Whats the 'parent' of a footnote?

Community Expert ,
Jul 09, 2019 Jul 09, 2019

Copy link to clipboard

Copied

Dear friends and wizards!

You all do know how to traverse the universe of footnotes in a document:

oFn = oDoc.FirstFnInDoc; 

  while (oFn.ObjectValid () === 1) {

    // do stuff

    }

    oFn = oFn.NextFnInDoc;

  }

With this method (and also with the Find method) I get footnotes from various environments:

  1. from the main flow
  2. from table cells (table footnotes)
  3. from a textframe within an anchored frame
  4. from a textframe within an anchored frame within a table cell

How can I find out, what's the 'parent environment' of a footnote is (to be precise: it's anchor object)?

I have not found something useful to determine this, because a particular function I want to script should work only on the ones mentioned first: the plain ordinary footnote.

For the curious: The task is to convert footnotes to endnotes.

Any ideas are highly welcome!

Edit

Do You think this could be useful:

Loop through the paragraphs and check whether there is a footnote anchor in it

IMHO the paragraphs are then only from the main flow, not from text cells or nested text frames.

TOPICS
Scripting

Views

479

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
Engaged ,
Jul 09, 2019 Jul 09, 2019

Copy link to clipboard

Copied

Hi Klaus,

footnote object has two properties (see page 510 in Scripting Guide):

1. InTextFrame - to get the text Frame, where footnote is in

2. TextLoc - to get the text Location object, and starting from here you will get the paragraph from textloc.obj

Hope this helps

Markus

EDIT:

Forgot

3. Element property for structured content

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
Community Expert ,
Jul 10, 2019 Jul 10, 2019

Copy link to clipboard

Copied

LATEST

Markus, thanks for Your suggestions.

However, I have tried with these already, but they report "undefined" in all cases independently of the cases 1 … 4 mentioned.

function CollectFootnotesInDoc (oDoc) {

// Arguments oDoc   Current document

// Returns   Number of Footnote collected in globarl array

var docStart, foundTR, k, nNotes=0, oFindParams, oFnTI, oTextItem, tloc;

   

  goFno.aoFNcollected.length = 0;                             // clear array

  docStart = oDoc.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf;

  tloc = new TextLoc (docStart, 0);

  oDoc.TextSelection = new TextRange (tloc, tloc); // essential

  oFindParams= Fno_GetFindParameters (7, "");     // Find footnote anchor

  foundTR = oDoc.Find(tloc, oFindParams);

  while (foundTR.beg.obj.ObjectValid()) { 

$.bp(true);

    var oX1 = foundTR.beg.obj.IntextFrame;        // undefined in all cases

    var oX2 = foundTR.beg.obj.IntextObj;          // "

    oFnTI = oDoc.GetTextForRange (foundTR, Constants.FTI_FnAnchor);

    for (k = 0; k < oFnTI.length; k++) {          // although k always 0 loop essential

      oTextItem = oFnTI;

//    var oX1 = oTextItem.obj.IntextFrame;        // undefined in all cases

//    var oX2 = oTextItem.obj.IntextObj;          // "

//    var oX3 = oTextItem.obj.FirstPgf.IntextFrame;        // undefined in all cases

//    var oX4 = oTextItem.obj.FirstPgf.IntextObj;          // "

      goFno.aoFNcollected.push(oTextItem.obj);    // object Fn

      nNotes += 1;                                // statistics

    }

    tloc = foundTR.end;                           // prepare for next find

    foundTR = oDoc.Find(tloc, oFindParams);

  }

  return nNotes;

} //--- end CollectFootnotesInDoc 

BTW the Find method is necessary to get the footnotes in the order of appearance in the document. The method oDoc.FirstFnInDoc … oFn.NextFnInDoc

gives the order of creation.

Today I will try my idea from the late evening: See Edited in the first post.

Edit

The following works as expected

function Fno_CollectFootnotes (oDoc) { //=== collect 'ordinary' footnotes in current document =========

// Arguments oDoc   Current document

// Returns   Number of Footnote collected in globarl array

// Comment   Collect only the footnotes from the main flow, not table footnotes

//           and not fn's from nested frames.

var oPgf, k, nNotes=0, oFindParams, aoTextItems, oTextItem;

  goFno.aoFNcollected.length = 0;                 // clear array

  oPgf = oDoc.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf;

  while (oPgf.ObjectValid()) {

    aoTextItems = oPgf.GetText(Constants.FTI_FnAnchor);

    for (k = 0; k < aoTextItems.length; k++) {    // there may be more than one

      oTextItem = aoTextItems;

      goFno.aoFNcollected.push(oTextItem.obj);    // object Fn

      nNotes += 1;                                // statistics

    }

    oPgf = oPgf.NextPgfInFlow;

  }

  return nNotes;

} //--- end Fno_CollectFootnotesInDoc 

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