-
1. Re: insert or replace last content
Jump_Over Aug 20, 2013 10:53 AM (in response to indegn5)Hi,
do mDoc.changeGrep() twice.
1. for remove last character if ";", ":" or "." (and unwanted space by the way)
2. for add "." to every end of bullet's para.
so:
var myDoc = app.activeDocument; app.findGrepPreferences = app.changeGrepPreferences = null; app.findGrepPreferences.bulletsAndNumberingListType = ListType.BULLET_LIST; app.findGrepPreferences.findWhat = "[\\.;:]\\s*$"; myDoc.changeGrep(); app.findGrepPreferences.findWhat = "(.)$"; app.changeGrepPreferences.changeTo = "$1."; myDoc.changeGrep(); app.findGrepPreferences = app.changeGrepPreferences = null;
Jarek
-
2. Re: insert or replace last content
Vamitul Aug 20, 2013 10:37 PM (in response to Jump_Over)you can do it with just one grep actualy (just the grep, no escaping):
find: (.)[\.;:]?\s*$
change: $1.
-
3. Re: insert or replace last content
indegn5 Aug 21, 2013 2:13 AM (in response to Vamitul)Thanks to both the G's....
everything is superb & fantastic, still my request is here.....
I do want to change fullstop only to the bullet of last paragraph. and rest of the bullets are like
Jareks' help!
app.findGrepPreferences.findWhat = "[\\.;:]\\s*$"; // superbVam's help! find: (.)[\.;:]?\s*$
// superbMany thanks for both the G's.....
-
4. Re: insert or replace last content
Vamitul Aug 21, 2013 3:48 AM (in response to indegn5)whoo.. well that is a bit more complicated.
For each
result you have to test first
if the next paragraph bulletsAndNumberingListType is not ListType.BULLET_LIST.
if so, myResult[i].changeGrep();
Remember always to iterate your array from the back. also there are quite a bit of catches. for example if the list is the last paragraph in the story, using paragraphs.nextItem() will return a invalid object. also of notice is the fact that the"nextItem()" method on colections is horribly slow, so for a large document you ether have to writhe your own method of getting the next paragraph, or have tons and tons of patience.
if this is a one time use only script or even a rarely used script, i say it's just not worth the trouble.
-
5. Re: insert or replace last content
indegn5 Aug 21, 2013 3:55 AM (in response to Vamitul)Thanks Vam,,
Could you help me to select, the last content of the paragraph.
as it tried above...
but the problem is ,,, is replacing the last text if there is no paragraphs after bullet and numbering paragraphs (counting -3, -2)
works correct, when there is a paragraph after bullet and numbering paragraphs..
so how can i mentioned ) .itemByRange(-3,-2).(-2, -2), if there is no paragraph after bullet... as you already said.. next paragraph. option....
thanks vam...
-
6. Re: insert or replace last content
Vamitul Aug 21, 2013 4:09 AM (in response to indegn5)ah.. could you restate that, please? I don't understand.
-
7. Re: insert or replace last content
indegn5 Aug 21, 2013 4:46 AM (in response to Vamitul)Sorry Vam for the confusion...
this is what i mentioned....
for(n=0; n< myResults.length;n++){
var fnd = myResults[n].paragraphs.lastItem().lines.lastItem();
if(fnd.insertionPoints.itemByRange(-3,-2).contents !== "."){ // if there is a paragraph below the bullet paragraph, it works fine... if not it replaces the last character with"."
fnd.insertionPoints.itemByRange(-3,-2).contents = "."
alert(fnd.insertionPoints.itemByRange(-3,-2).contents)
}
}
eg. • vamitul;
• vamitul;
• vamitul; // now the semicolon of the last paragraph will be replaced with "." itemByRange(-3,-2).
Dummy text paragraph of this what when dummy text. (paragraph below the last bullet).
eg2. • vamitul;
• vamitul;
• vamitul;
• vamitul; // if there is no paragraph below... now character "l" is replaced with "." itemByRan(-3,-2) goes to l and change it......
Again sorry if im confusing..... vam..
-
8. Re: insert or replace last content
Vamitul Aug 21, 2013 5:00 AM (in response to indegn5)there are multiple problems with your code.
For one, what if you don't have any punctuation at the end of the list? per your example:
• vamitul;
• vamitul;
• vamitul /// your code will change this line to vamitu.
Dummy text parag
as for your example, you have to test if that paragraph is the last one in the story (for example myResults[n].parentStory.paragraphs.nextItem(myResults[n].paragraphs[0]).isValid will test if there is another paragraph after your found one). if it is the last one, you will have to treat it as a special case and adjust the insertionPoints range.
also using insertionPoints is not the most fortunate idea.. (see my point above). instead do a changeGrep() on the found text.
-
9. Re: insert or replace last content
indegn5 Aug 21, 2013 5:43 AM (in response to Vamitul)Superb Vam & Jarek!....
I 'll test it and let me open another thread..... for the course of benefit of the forum...
Thanks Vam..!!!! excellent reply.
Thanks Jarek... for the quick approachable hint.....


