Skip to main content
Klaus Göbel
Legend
May 23, 2018
Question

paragraph inside a textinset

  • May 23, 2018
  • 2 replies
  • 1467 views

How can I find out, if a paragraph is inside a textinset?

Is there any (hidden) property, that can tell me?

This topic has been closed for replies.

2 replies

frameexpert
Community Expert
Community Expert
May 23, 2018

Hi Klaus,

It depends on what I am trying to do. Most of the time, I want paragraphs that aren't in a text inset, so I use a function like this to collect paragraphs that aren't in text insets:

// Get paragraphs not in text insets code. -----------------------------------

FCFB.getParagraphs = function (doc) {

   

    var pgfs = [], textList, i, count, inInset = 0, tbl;

   

    textList = doc.MainFlowInDoc.GetText (Constants.FTI_TblAnchor | Constants.FTI_PgfBegin | Constants.FTI_TextInsetBegin | Constants.FTI_TextInsetEnd);

    count = textList.length;

    for (i = 0; i < count; i += 1) {

        if (textList.dataType === Constants.FTI_TextInsetBegin) {

            inInset = 1;

        }

        else if (textList.dataType === Constants.FTI_TextInsetEnd) {

            inInset = 0;

        }

        else if (textList.dataType === Constants.FTI_PgfBegin) {

            if (inInset === 0) {

                pgfs.push (textList.obj);

            }

        }

        else if (textList.dataType === Constants.FTI_TblAnchor) {

            if (inInset === 0) {

                tbl = textList.obj;

                FCFB.getTblPgfs (tbl, pgfs);

            }

        }

    }

    // Get the master and reference pages paragraphs.

    FCFB.getMasterPagePgfs (doc, pgfs);

    FCFB.getRefPagePgfs (doc, pgfs);

   

    // Get any paragraphs inside of anchored frames.

    FCFB.getAFramePgfs (doc, pgfs);

   

    // Get any paragraphs inside of footnotes.

    FCFB.getFnPgfs (doc, pgfs);

   

    // Get any paragraphs inside of non-flow text frames on body pages.

    FCFB.getBodyPageTextFramePgfs (doc, pgfs);

    return pgfs;

};

As you can see, I have some other functions I call to make sure I have ALL of the non-text inset paragraphs. But it depends on the task.

Rick

www.frameexpert.com
Klaus Göbel
Legend
May 23, 2018

Hi Russ, hi Rick,

thanks a lot for your answers.

I'm using find() or NextGraphicInDoc(that also can be in a TextInset ) ;

So I will find a parapgraph.

Then I have to find out, if it is in a TextInset.

The only way is, to go backward (PrevPgfInFlow) until (or not) I find FTI_TextInsetBegin or FTI_TextInsetBegin. Then I'll have to find out, if this TextInset is in another TextInset.

Using FTI_TextInsetBegin returns only the first paragraph, but TextInsets can have dozens of paragraphs.

So if this document has only few TextInsets, I have to go back a long way for every paragraph.

So my hope was, that there's a simpel way to find out. It seems, that I have got go the long way.

Legend
May 23, 2018

Hi Klaus,

It still seems reasonably simple to me, if my TextRange-based theory is correct. If I were you, I would just search all insets in the document. It seems like a lot of processing, but I bet it would happen very quickly. Something like this (again incomplete, untested):

var doc = app.ActiveDoc;

var pgf = /* your "find" code to get the pgf in question */;

var pgfIsInTheInset = false;

var textInset = doc.FirstTiInDoc;

while(textInset.ObjectValid() && !pgfIsInTheInset)

{

  var tempPgf = textInset.TextRange.beg.obj;

  while(tempPgf.ObjectValid() && !pgfIsInTheInset)

  {

    if(tempPgf.id == pgf.id) pgfIsInTheInset = true;

    tempPgf = tempPgf.NextPgfInFlow;

  }

  textInset = textInset.NextTiInDoc;

}

/* evaluate pgfIsInTheInset now */

This is all dependent upon whether the TextRange approach will work. As long as it is the actual text range of the whole inset, I think it should. If it is the text range of the inset anchor only, it will not. The documentation suggests the first definition.

Russ

Legend
May 23, 2018

Hi Klaus,

I don't know a direct method, but I think you could iterate through the paragraphs in the inset to find out. Something like (untested, incomplete):

var pgfIsInTheInset = false;

var pgf = /* some code to get the pgf in question */;

var textInset = /* some code to get the TiText (inset) object */;

var tempPgf = textInset.TextRange.beg.obj;

while(tempPgf.ObjectValid() && !pgfIsInTheInset)

{

  if(tempPgf.id == pgf.id) pgfIsInTheInset = true;

  tempPgf = tempPgf.NextPgfInFlow;

}

/* evaluate pgfIsInTheInset now */

Hope this helps, maybe somebody knows a simpler method.

Russ