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

I need a GREP or script to remove specific sequences or paragraph styles.

Participant ,
Apr 20, 2022 Apr 20, 2022

Copy link to clipboard

Copied

I'm still far too new to scripting to understand how to write this out and i don't believe find/change or GREP can do what i want but what needs to happen is to look at a selected text frame, find whenever a paragraph with style A is directly followed by a paragraph with style B, and remove both paragraphs, while ignoring any other combination of styling.

 

For the background here, I'm using data merge to import a list of terms (Term) and definitions (Def), with a another set of columns specifying if the Term/Def is used in a specific book. This is defined by a character (X) placed in the cell if its included in the book. I then use the Inline Merge script by Loic to fill a text frame with all the data, each having a para style.

 

The Merge fields look like this:

<<Book>> (style A)

<<Term>> (style C)

<<Def>> (style B)

 

On words that are included in the book the styling works as intended with 3 paragraphs generated:

X (style A)

Sample Term (style C)

Sample Def (style B)

 

However when using the Inline Merge script with the option to Remove Blank Lines for Empty Fields checked a curious thing happens for words that aren't included in the book that i want to take advantage of; the term now gets styled with style A followed by the definition styled properly as style B, example below:

 

Sample Term (style A)

Sample Def (style B)

 

So now i want to remove all terms and definitions not included in the book which can be seen as a paragraph styled A followed by a paragraph styled B, while leaving any sequences of para styles A-C-B.

 

Can this be done within indesign natively? and if not can someone help with writing a script for this? Bonus points if activating the script can initially run the Inline merge script, followed by the above actions, and the again followed by removing any paragraph with styling A, as that paragraph is only necessary for determining if the word should be included. 

 

Thanks

-Austin

TOPICS
How to , Scripting

Views

819

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 , Apr 20, 2022 Apr 20, 2022

I see that the InlineMerge always remove empty line.
You can do this... 
1. Add a character before the merge for the <<Sample Book 1>
2. Do your InligneMerge (empty line will just have a @
3. Do a GREP Find @\r(.+\r){2} with nothing in change to
4. Do another one to delete the remaining ^@

Screen 1.png

Votes

Translate

Translate
Community Expert ,
Apr 20, 2022 Apr 20, 2022

Copy link to clipboard

Copied

Can you do your weeding in the data sheet before doing the merge? 

Sort the excel sheet, First by the column that defines inclusion in the book, and then by whatever column you need your data sort by. That will put all of the lines that belong in a given book together, and you can include only those lines when you do the merge.

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
Participant ,
Apr 20, 2022 Apr 20, 2022

Copy link to clipboard

Copied

Ideally no, one terms list is used for more than half a dozen different books, each book having different terms included but multiple books can have the same terms. sorting the list for every book doesn't save the team any time, so i'm trying to figure out how to use the same set of data for different books. with 100+ books our team makes a year i'm trying to automate and simply the layout process for a team of designers as we move away from iBooks Author to InDesign.

 

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 ,
Apr 20, 2022 Apr 20, 2022

Copy link to clipboard

Copied

Since this is an ongoing need, it might be worth your while to look a one of the catalog plug-ins to handle this. Something like EasyCatalog would let you quickly group and choose your data (within InDesign) based on the content of that field. Inline merge is a built-in option with those plug-ins. 

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 ,
Apr 20, 2022 Apr 20, 2022

Copy link to clipboard

Copied

Don’t enable Remove Blank Lines for Empty Fields. Do your cleaning after the merge to remove empty line.

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
Participant ,
Apr 20, 2022 Apr 20, 2022

Copy link to clipboard

Copied

I'm not trying to remove the empty lines, i'm trying to remove entire paragraphs quickly and preferably automatically based on whether a term is included, denoted by a character being present in a data field. I'm trying to automatically remove paragraphs based on specific patterns, as explained in the post.

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 ,
Apr 20, 2022 Apr 20, 2022

Copy link to clipboard

Copied

If you leave your empy entry in, you can use this GREP to delete them and the term/def after it.

^$\r.+\r.+\r

 

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
Participant ,
Apr 20, 2022 Apr 20, 2022

Copy link to clipboard

Copied

Hmm, for some reason regardless of turning that option on or off, an empty entry in not being added, it is again just creating two paragraphs on the entries with a blank field, and three on entries with a non-blank field. It seems this is a specific feature of Inline Merge, and i don't know if i can change that at all

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
Participant ,
Apr 20, 2022 Apr 20, 2022

Copy link to clipboard

Copied

Also running that Grep didn't seem to work on a test doc using regular data merge, which is able to produce the empty lines.

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 ,
Apr 20, 2022 Apr 20, 2022

Copy link to clipboard

Copied

It would help to have access to some data file and doc to better help you.

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
Participant ,
Apr 20, 2022 Apr 20, 2022

Copy link to clipboard

Copied

Here is an example doc and data file with dummy text. of course i'm using the Inline Merge script as well.

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 ,
Apr 20, 2022 Apr 20, 2022

Copy link to clipboard

Copied

Which columns should be associated to <<AC and DC Theory>>? All of the Sample Book 1 to 9?

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
Participant ,
Apr 20, 2022 Apr 20, 2022

Copy link to clipboard

Copied

that was one of the book names, i forgot to swich that out. it equates to one of the sample book fields. sorry about that.

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 ,
Apr 20, 2022 Apr 20, 2022

Copy link to clipboard

Copied

I see that the InlineMerge always remove empty line.
You can do this... 
1. Add a character before the merge for the <<Sample Book 1>
2. Do your InligneMerge (empty line will just have a @
3. Do a GREP Find @\r(.+\r){2} with nothing in change to
4. Do another one to delete the remaining ^@

Screen 1.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
Participant ,
Apr 20, 2022 Apr 20, 2022

Copy link to clipboard

Copied

This worked out great, thanks so much!

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
Participant ,
Apr 21, 2022 Apr 21, 2022

Copy link to clipboard

Copied

LATEST

I made a slight modification to the GREP you provided to account for the end of the story content, since there wasn't a paragraph return after the final entry. Adding for any future thread visitors.

@\r(.+\r|.+$){2}

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