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

Check if a nested grep style exists! …

LEGEND ,
Mar 18, 2017 Mar 18, 2017

Copy link to clipboard

Copied

Hi Scripters,

Add a nested grep style to a para style is easy! … but how to check if this nested grep style already exists? 

and, accessorily, how to remove it? 

Thanks in advance!

(^/)

TOPICS
Scripting

Views

1.2K

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 , Mar 18, 2017 Mar 18, 2017

You could check the name or perhaps better the id number of the appliedCharacterStyle PLUS the value of the grepExpression. If both are the same in a particular nestedGrepStyle you found the one you were looking for. If it's important if a style is used in a particular stacking order, you could also factor in the index number of the found nestedGrepStyle .

Regards,
Uwe

Votes

Translate

Translate
Community Expert ,
Mar 18, 2017 Mar 18, 2017

Copy link to clipboard

Copied

Hi Obi-wan,

what did you try so far?

For paragraph styles we have the property:

nestedGrepStyle

And that object collection has the properties:

appliedCharacterStyle

grepExpression

Regards,
Uwe

// EDIT

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 ,
Mar 18, 2017 Mar 18, 2017

Copy link to clipboard

Copied

The other question about removing GREP styles:

You have to do it one by one if you want to remove them all.

There is a bug with InDesign's nested GREP styles that would not allow the following and throws an error:

myParaGraphStyle.nestedGrepStyles.everyItem().remove();

Wheras this would work:

var nestedGREPStyles = myParaGraphStyle.nestedGrepStyles.everyItem().getElements();

for(var n=nestedGREPStyles.length-1; n>=0;n--)

{

nestedGREPStyles.remove();

}

Regards,
Uwe

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
LEGEND ,
Mar 18, 2017 Mar 18, 2017

Copy link to clipboard

Copied

Uwe,

Thanks!

About the first point, I know these codes and how to add a nested grep style to an existent para style!

my difficulty is how to verify if a NGS I want to add already exists in the para style! If not, I add it, if yes, I do nothing! The problem is to do it with several NGS to be checked too!

(^/)

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 ,
Mar 18, 2017 Mar 18, 2017

Copy link to clipboard

Copied

You could check the name or perhaps better the id number of the appliedCharacterStyle PLUS the value of the grepExpression. If both are the same in a particular nestedGrepStyle you found the one you were looking for. If it's important if a style is used in a particular stacking order, you could also factor in the index number of the found nestedGrepStyle .

Regards,
Uwe

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
LEGEND ,
Mar 18, 2017 Mar 18, 2017

Copy link to clipboard

Copied

Yeap!

Do you mean something like this:

var myDoc = app.activeDocument,

myFootnotePStyle = myDoc.paragraphStyles.item("Footnote"),

myNestedGrepStyles = myFootnotePStyle.nestedGrepStyles.everyItem().getElements(),

N = myNestedGrepStyles.length;

for( var n = N-1; n >=0; n--) {

    myNGS = myNestedGrepStyles;

    if ( myNGS.appliedCharacterStyle.name == "NB"  &&  myNGS.grepExpression == "~>=" ) alert("Gotcha!  =D")

    else alert("Bordel de m… !*  :(")

    }

[ * French rudeness!  =D ]

(^/) 

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 ,
Mar 18, 2017 Mar 18, 2017

Copy link to clipboard

Copied

Yes.

Be aware that you have to escape characters for expressions like that:

"\d" => "\\d"

Otherwise your if statement will fail.

Regards,
Uwe

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 ,
Mar 18, 2017 Mar 18, 2017

Copy link to clipboard

Copied

And another thing to note:
We must be aware, that one can add a particular GREP style more than one time to a paragraph style.

Have a nice weekend!

Uwe

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 ,
Mar 18, 2017 Mar 18, 2017

Copy link to clipboard

Copied

And that property nestedGrepStyles is not only a property of paragraphStyles, but also a property of e.g. the Text object.
That means a nested GREP style could also be there as an override of the applied paragraph style.

Now again:

Have a nice weekend! 🙂

Uwe

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
LEGEND ,
Mar 18, 2017 Mar 18, 2017

Copy link to clipboard

Copied

Thanks! I'll take a look!

You too!

(^/)

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
Explorer ,
Jun 25, 2019 Jun 25, 2019

Copy link to clipboard

Copied

LATEST

thank you for this. It was just what I was looking for!

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