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

paragraph inside a textinset

Enthusiast ,
May 23, 2018 May 23, 2018

Copy link to clipboard

Copied

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

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

TOPICS
Scripting

Views

777

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 ,
May 23, 2018 May 23, 2018

Copy link to clipboard

Copied

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

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 ,
May 23, 2018 May 23, 2018

Copy link to clipboard

Copied

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

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
Enthusiast ,
May 23, 2018 May 23, 2018

Copy link to clipboard

Copied

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.

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
Mentor ,
May 23, 2018 May 23, 2018

Copy link to clipboard

Copied

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

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
Mentor ,
May 23, 2018 May 23, 2018

Copy link to clipboard

Copied

I just noticed that the paragraph object has a Locked property which has something to do with insets. But I don't know if that is reliable for what you need.

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
Enthusiast ,
May 23, 2018 May 23, 2018

Copy link to clipboard

Copied

Hi Russ,

this Locked property doesn't help in any way.

But thanks for your suggestion

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 ,
May 23, 2018 May 23, 2018

Copy link to clipboard

Copied

Hi Klaus, What exactly do you want to find? Graphics in text insets or graphics that aren't in text insets? Is there anything common about the graphics, for example, those in anchored frames? Or is it just imported graphics,etc.? I think you will find that my approach isn't as difficult as it looks. Once you put together a few of the necessary functions, you can plug them in just about anywhere. For example, in my approach, I can easily locate paragraphs outside or inside of text insets with just simple modifications of my functions. -Rick

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
Enthusiast ,
May 23, 2018 May 23, 2018

Copy link to clipboard

Copied

Hi Rick,

I have several requirements.

I want to find graphics using NextGraphicInDoc  that are outside of TextInsets. No matter if they are anchored or unanchored frames.

And I want to find empty paragraphs using find().

I will test your proposal as well as Russ' proposal.

I'll give you feedback.

Thanks a lot for your support

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 ,
May 23, 2018 May 23, 2018

Copy link to clipboard

Copied

Unanchored frames are always going to be outside of any text insets. When you import a text inset, you are importing one of the flows so you don't get any unanchored frames that are in the text inset document.

Do you have to use NextGraphicInDoc? Can't you just collect the graphics that are either in or not in text insets? If you collect the graphics all at once in an array (or perhaps an array of ids or Uniques), then you should be able to navigate them later.

I rarely use find() to locate paragraphs. I would use a function to navigate through the paragraphs like I provided above. For each one, I would use a function to see if it is empty:

function pgfIsEmpty (pgf) {

   

    var textItems = pgf.GetText(Constants.FTI_PgfEnd);

    if (textItems[0].offset === 0) {

        if (pgf.PgfNumber === "") {

            if (pgf.BottomSeparator === "") {

                if (pgf.TopSeparator === "") {

                    return true;

                }

            }

        }

    }

    return false;

}

A more useful function is one that will consider paragraphs with spaces only to be empty as well. I can't find one right now, but I know I have done this in some of my scripts.

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
Enthusiast ,
May 23, 2018 May 23, 2018

Copy link to clipboard

Copied

Unanchored frames are always going to be outside of any text insets.

I'm aware of that.

My Script to find empty paragraphs is finished. It also considers, if "empty" paragraphs are NOT empty, but contain e.g CHR$(13) which comes from textcopy from Word

Do you have to use NextGraphicInDoc? Can't you just collect the graphics that are either in or not in text insets? If you collect the graphics all at once in an array (or perhaps an array of ids or Uniques), then you should be able to navigate them later.

NextGraphicInDoc is the easiest way.

But my question is not only about find and NextGraphicInDoc.These are only examples.

It is more in general.

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
Enthusiast ,
May 23, 2018 May 23, 2018

Copy link to clipboard

Copied

LATEST

Here's my solution:

var goDoc = app.ActiveDoc;

var gaTIs = fGetTextInsets(goDoc);  // gather all the TextInsets

var goFlow = goDoc.MainFlowInDoc;

var goPgf = goFlow.FirstTextFrameInFlow.FirstPgf;

var goPgfReturnObj; 

while (goPgf.ObjectValid())

    {

    goPgfReturnObj = IsInTextInset(goDoc,goPgf);    // is this pgf in a TextInset?

    goPgf = goPgfReturnObj.Pgf;   //  unchanged, if not in a TextInset , changed to last Pgf of the TextInset, if in a Textinset

   

    if (!goPgfReturnObj.IsInInset)

        {

        GetPgfText(goPgf);

        }

   

        goPgf = goPgf.NextPgfInFlow;

       

    }

function IsInTextInset(foDoc,fPgf)

{

var loReturn = new Object();

loReturn.Pgf = fPgf;

loReturn.IsInInset = false;

var textInset = foDoc.FirstTiInDoc;

while(textInset.ObjectValid())

    {

    var tempPgf = textInset.TextRange.beg.obj;

   

     if(tempPgf.id == fPgf.id)

        {

        loReturn.Pgf  = textInset.TextRange.end.obj;    // jump to the end of the TextInset

        loReturn.IsInInset = true;

        break;

        }

       

    textInset = textInset.NextTiInDoc;

    }

   

    return loReturn;

}

function fGetTextInsets(foDoc)

{

var laTIs = [];

var loTI = foDoc.FirstTiInDoc;

while (loTI.ObjectValid())

    {

     laTIs.push(loTI);

     loTI = loTI.NextTiInDoc;

    }

return laTIs;

}

  

function GetPgfText(foPgf)

{

var lsText = foPgf.GetText (Constants.FTI_String);

var  locPgfText = "";

for (var i = 0; i <= lsText.length -1; i++)

       {

        locPgfText = locPgfText + lsText.sdata;

        if (locPgfText > "") break;     // Only first line

        }

       

  if (locPgfText > "")

        {

        $.writeln(locPgfText);

        }

}

It works also, if there's a TextInset in a TextInset.

Thanks to Russ, who pointed me to TextRange.

Thanks to Rick and Russ, who helped me find this solution.

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