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

I want to remove the empty paragraph mark using GREP search?

New Here ,
May 29, 2024 May 29, 2024

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

TOPICS
EPUB , Scripting

Views

128

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

correct answers 1 Correct answer

Community Expert , May 30, 2024 May 30, 2024

Hi @Aysha37173136xpeg , 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 = nul
...

Votes

Translate

Translate
Community Expert ,
May 30, 2024 May 30, 2024

Copy link to clipboard

Copied

Hi @Aysha37173136xpeg , 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:

 

Screen Shot 18.png

 

Screen Shot 19.png

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 Expert ,
May 30, 2024 May 30, 2024

Copy link to clipboard

Copied

You can also remove empty (blank) paragraphs with a common search and replace.

 

  • Edit / Find Change
  • Find what: ^p^p

— (note that ^p is the standard computer metacharacter for paragraph marks)

— Search for 2 in a row and replace with 1.

  • Change to: ^p

BeviChagnonPubComcom_0-1717094565582.png

 

 

|    Bevi Chagnon   |  Designer & Technologist for Accessible Documents
|    Classes & Books for Accessible InDesign, PDFs & MS Office |

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 ,
May 30, 2024 May 30, 2024

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 

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 Expert ,
May 31, 2024 May 31, 2024

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.

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 Expert ,
Jun 01, 2024 Jun 01, 2024

Copy link to clipboard

Copied

LATEST

Thanks!

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