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

Grep in a text range

Explorer ,
Mar 26, 2019 Mar 26, 2019

I'm trying to run a grep on all the text between two subheads -- I can get the range (mySection)  but range.findGrep() returns garbage?

code below

alert(fns) pops up a list of [object TextStyleRange - 10 or more

alert(fns.length) pops up 1

Any suggestions? (I suspect it's something simple)

Thanks

=====

var startRenumbering="Sub";

sel = app.selection[0];


  app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;

  app.findGrepPreferences.findWhat="\r";

  app.findGrepPreferences.appliedParagraphStyle=startRenumbering;

   var x = sel.parentStory.findGrep();

   for(section=0;section<x.length-1;section++){

       mySection=sel.parentStory.characters.itemByRange(x[section].index, x[section+1].index);

       app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;

       app.findGrepPreferences.appliedCharacterStyle="fr";

        // app.changeGrepPreferences.changeTo="fnNum";

        var fns = mySection.findGrep();

   alert(fns.length);

  }

 

TOPICS
Scripting
1.1K
Translate
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

Community Expert , Mar 26, 2019 Mar 26, 2019

Change the line

mySection=sel.parentStory.characters.itemByRange(x[section].index, x[section+1].index)

to the following line

mySection=sel.parentStory.characters.itemByRange(x[section].index, x[section+1].index).getElements()[0];

The mySection in your code was character object, resolving it seems to be working. I am not sure why this happened, pondering over it.

-Manan

Translate
Community Expert ,
Mar 26, 2019 Mar 26, 2019

A sample document with a bit of description on what is required would help us make some suggestions

Translate
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 26, 2019 Mar 26, 2019

SUBHEAD (with Sub paragraph style)

multiple text paragraphs with note numbers interspersed. The note numbers have a "fr" character style

SUBHEAD TWO (with Sub pStyle)

I need to select the text between the two Subheads -- find the note numbers -- and renumber them starting from 1.

The script above returns the text between the two subheads (mySection) -- alert(mySection.contents) shows the proper text

IF fns (in the line before last of the script) was an array of the grep results I could step through it and change the numbers. But it isn't.

Translate
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 ,
Mar 26, 2019 Mar 26, 2019

Change the line

mySection=sel.parentStory.characters.itemByRange(x[section].index, x[section+1].index)

to the following line

mySection=sel.parentStory.characters.itemByRange(x[section].index, x[section+1].index).getElements()[0];

The mySection in your code was character object, resolving it seems to be working. I am not sure why this happened, pondering over it.

-Manan

Translate
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 26, 2019 Mar 26, 2019
LATEST

Thanks -- that worked. If you figure out why the change was needed I'd like to know for the future.

Translate
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