Copy link to clipboard
Copied
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
=====
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);
}
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
Copy link to clipboard
Copied
A sample document with a bit of description on what is required would help us make some suggestions
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Thanks -- that worked. If you figure out why the change was needed I'd like to know for the future.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now