Copy link to clipboard
Copied
Hi all,
Wondering if anyone can help with how I change the apply style in the GREP section of the "Paragraph Style Options" box?
I have a Paragraph Style: "Codes + Prices"
The Grep "Apply Style:" Character Style is "Bullet Bold Subhead"
The Grep "To Text:" (?<=\t )\d{1,4}+\+
I want to change the "Apply Style:" Character Style from "Bullet Bold Subhead" to: "Font Bold"
Apologies for not putting any script up to start this off but all the help I have found has been for the Find/Change box, i'm finding it hard to find anything to tell me how to do this in the paragraph styles, does anyone have a script I can start with.
Thanks in advance, Bren
Hi Bren,
I think the following code should do what you need
...var pStyleToChange = app.activeDocument.paragraphStyles.itemByName("Codes + Prices")
var cStyle = app.activeDocument.characterStyles.itemByName("Font Bold")
if(pStyleToChange.isValid && cStyle.isValid)
{
for(i = 0; i < pStyleToChange.nestedGrepStyles.length; i++)
{
if(pStyleToChange.nestedGrepStyles.appliedCharacterStyle.name == "Bullet Bold Subhead")
pStyleToChange.nestedGrepStyles.appliedCharacterStyle = cSty
Copy link to clipboard
Copied
you want to change character style name from "Bullet Bold Subhead" to: "Font Bold"
Copy link to clipboard
Copied
Maybe its just this, but i have trouble understand what you try to achieve.
Object style » choose a Paragraph-Style » holds GREP » choose Character style
In object style you choose which paragraph-style is used if object is a textbox. Open up the window for paragraph-styles and character-sytles. In paragraph style you can edit GREP and choose a character-style or create a new one. If you want to make changes to these styles, you have to access them via the corresponding palette.
Copy link to clipboard
Copied
Hi,
I need to change the "Apply Style:" to another style. I have uploaded a pic to explain this better.
Thanks, Bren
Copy link to clipboard
Copied
Hopefully this image will help, greps are in so many different places it's hard to pinpoint which one I am talking about.
I work in Javascript by the way
Thanks, Bren
Copy link to clipboard
Copied
GREP is only available in paragraph-styles and in Find/Replace-Dialog, as far as i know, what, if there are, is not as far tho.
But isnt it this, just to klick the specific grep, and change the character-style for that?
Copy link to clipboard
Copied
Hi, yes that's what I need the script to do, this is for thousands of pages so a big ask manually
Copy link to clipboard
Copied
Or this no-brainer, just delete the "Bullet Bold Subhead", and because its "in use" (by the grep in your parastyle), InDesign asks for replacement.
Copy link to clipboard
Copied
Its in use somewhere else so cannot be deleted, do you by any chance have any of this in script as I know what I need to do but have no way of doing it.
Copy link to clipboard
Copied
Found a forum post by Kasyan Servetsky , this looks promising to alter:
"The script adds a grep style to every paragraph style including styles in groups."
Main();
function Main() {
var doc = app.activeDocument,
parStyles = doc.allParagraphStyles,
charStyle = doc.characterStyles.item(“Figure numbers”),
parStyle, i, grepStyle;
if (!charStyle.isValid) doc.characterStyles.add({name:”Figure numbers”, fontStyle:”Bold”});
for (i = 1; i < parStyles.length; i++) {
parStyle = parStyles;
grepStyle = parStyle.nestedGrepStyles.add();
grepStyle.grepExpression = “d+”;
grepStyle.appliedCharacterStyle = charStyle;
}
}
https://indesignsecrets.com/topic/script-to-insert-grep-style-in-all-paragraph-styles
Copy link to clipboard
Copied
Hi Bren,
I think the following code should do what you need
var pStyleToChange = app.activeDocument.paragraphStyles.itemByName("Codes + Prices")
var cStyle = app.activeDocument.characterStyles.itemByName("Font Bold")
if(pStyleToChange.isValid && cStyle.isValid)
{
for(i = 0; i < pStyleToChange.nestedGrepStyles.length; i++)
{
if(pStyleToChange.nestedGrepStyles.appliedCharacterStyle.name == "Bullet Bold Subhead")
pStyleToChange.nestedGrepStyles.appliedCharacterStyle = cStyle
}
}
So what the code does is first find the paragraph style whose grep style is to be changed and also the character style that is to be used as a replacement. If both are found we iterate through all the grepstyles in the paragraphstyle and find the one with the character style whose name matches the one we need to change and if it is found we replace it.
-Manan
Copy link to clipboard
Copied
Thank you so much Manan that has worked perfectly, no adjustments or problems.
Very thankful, Bren