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!
(^/)
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
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
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
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!
(^/)
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
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 ]
(^/)
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
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
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
Copy link to clipboard
Copied
Thanks! I'll take a look!
You too!
(^/)
Copy link to clipboard
Copied
thank you for this. It was just what I was looking for!