Copy link to clipboard
Copied
I am using the following code to find the empty paragraph mark the code finds the search but replace is not done perfectly.
Dim Occurances
indesignApplication.FindGrepPreferences = InDesign.idNothingEnum.idNothing
indesignApplication.ChangeGrepPreferences = InDesign.idNothingEnum.idNothing
indesignApplication.FindChangeGrepOptions.includeFootnotes = False
indesignApplication.FindChangeGrepOptions.includeHiddenLayers = False
indesignApplication.FindChangeGrepOptions.includeLockedLayersForFind = False
indesignApplication.FindChangeGrepOptions.includeLockedStoriesForFind = False
indesignApplication.FindChangeGrepOptions.includeMasterPages = False
indesignApplication.FindGrepPreferences.findwhat = "\r(?=\r)"
Occurances = indesignApplication.ActiveDocument.FindGrep()
indesignApplication.ChangeGrepPreferences.changeto = ""
If Occurances.Count <> 0 Then
For foundindex As Integer = 1 To Occurances.Count
Dim foundItem = Occurances.Item(foundindex)
Dim insertionPoint As InsertionPoint = foundItem.InsertionPoints.FirstItem
foundItem.Select()
foundItem.showtext
indesignApplication.Selection(1).ChangeGrep()
Next
End If
indesignApplication.FindGrepPreferences = InDesign.idNothingEnum.idNothing
indesignApplication.ChangeGrepPreferences = InDesign.idNothingEnum.idNothing
Hi @AyshaIsmail , I use this function for find and change—it‘s ExtendScript (not sure what your code is?)
//replaces multiple returns with single return
grepSearch("\\r+", "\\r");
//replaces multiple tabs with single tab
grepSearch("\\t+", "\\t");
/**
* Document Grep find and change
* @ param f the find grep string
* @ param c the change grep string
* @ return void
*/
function grepSearch(f,c){
app.findGrepPreferences = app.changeGrepPreferences = app.findChangeGrepOptions = null;
Copy link to clipboard
Copied
Hi @AyshaIsmail , I use this function for find and change—it‘s ExtendScript (not sure what your code is?)
//replaces multiple returns with single return
grepSearch("\\r+", "\\r");
//replaces multiple tabs with single tab
grepSearch("\\t+", "\\t");
/**
* Document Grep find and change
* @ param f the find grep string
* @ param c the change grep string
* @ return void
*/
function grepSearch(f,c){
app.findGrepPreferences = app.changeGrepPreferences = app.findChangeGrepOptions = null;
app.findChangeGrepOptions.properties = {includeFootnotes:false, includeHiddenLayers:false,
includeMasterPages:false, includeLockedStoriesForFind:false, includeLockedLayersForFind:false}
app.findGrepPreferences.findWhat = f;
app.changeGrepPreferences.changeTo = c;
app.activeDocument.changeGrep( true )
}
Before and after:
Copy link to clipboard
Copied
You can also remove empty (blank) paragraphs with a common search and replace.
— (note that ^p is the standard computer metacharacter for paragraph marks)
— Search for 2 in a row and replace with 1.
Copy link to clipboard
Copied
Before I used indesignApplication.Selection(1).ChangeGrep(). Now from ur code I change it to indesignApplication.ActiveDocument.ChangeGrep(True) .
The code is working fine. Thank you @rob day
Copy link to clipboard
Copied
@rob day : A small detail: your
grepSearch("\\r+", "\\r");
works, but it replaces single returns as well, so it does too much. This is more efficient:
grepSearch("\\r\\K\\r+", "");
A small detail, true.
P.
Copy link to clipboard
Copied
Thanks!