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

Is Find() dependable or should I use something else?

New Here ,
Feb 05, 2014 Feb 05, 2014

Copy link to clipboard

Copied

I'm trying to use Doc.Find() to find paragraphs that have changebars. Is Find() advisable generally or should I spend my time using some other method, like iterating through Pgf objects?

I'm also assuming that the place to look for changebars is the Pgf objects (Pgf.ChangeBar), not the TextItem objects. Am I on the right track?

Thanks,

Mark

TOPICS
Scripting

Views

718

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 ,
Feb 05, 2014 Feb 05, 2014

Copy link to clipboard

Copied

I don't like to use Find in FrameScript for this type of thing, so I wouldn't recommend it with ExtendScript either. I prefer to inerate through paragraphs, then check each paragraph for CharPropsChange text items. You can't just look at the paragraph level, because you could have text inside the paragraph that has change bars applied. 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
New Here ,
Feb 05, 2014 Feb 05, 2014

Copy link to clipboard

Copied

So is this a reasonable way to find a changebar:

var doc = app.ActiveDoc;

var pgf = doc.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf;

while(pgf.ObjectValid()) {

    var textitems = pgf.GetText(Constants.FTI_CharPropsChange);

   

    for (var i=0; i < textitems.len ; i +=1)

    {

        var x = textitems.idata & Constants.FTF_CHANGEBAR

        if (x == 0) {

           $.writeln ('I have a changebar');

        }

    }

    

    pgf = pgf.NextPgfInFlow;

}

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
New Here ,
Feb 06, 2014 Feb 06, 2014

Copy link to clipboard

Copied

My code above was not correct, it did not find changebars. I had to discover some arcane (to me at least) bitwise operator knowledge that is not included in the Fm docs. I realized that to find a changebar, the result of ANDing TextItem.idata and Constants.FTF_CHANGEBAR must be greater than 0. So my code worked when I changed this line:

     if (x == 0) {

To this:

     if (x > 0) {

Here is the working code (corrections and suggestions welcome!):

var doc = app.ActiveDoc;

var pgf = doc.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf;

while(pgf.ObjectValid()){

    var textitems = pgf.GetText(Constants.FTI_CharPropsChange);

   

    for (var i=0; i < textitems.len ; i +=1)

    {

        // The result of the AND must be greater than 0 or no changebar.

        var x = textitems.idata & Constants.FTF_CHANGEBAR;

        if (x > 0) {

           $.writeln ('I have a changebar');

        }

    }

    pgf = pgf.NextPgfInFlow;

}

Now what the significance of the TextItem.idata field is, is still beyond me. The docs say it is "The ID of the object if the text item is an object." But why would you need to AND that ID with some constant?  Mark

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 Beginner ,
Oct 23, 2019 Oct 23, 2019

Copy link to clipboard

Copied

LATEST

It looks like the FOR loop is missing the array index "i" in the textitems. Your code works for me when I added the "[i]" indice:

    for (var i=0; i < textitems.len ; i +=1)
    {
        // The result of the AND must be greater than 0 or no changebar.
        if (textitems[i].idata & Constants.FTF_CHANGEBAR) {
           $.writeln ('I have a changebar');
        }
    }

 

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