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

GREP within paragraph style - Character Style change

Guest
Dec 07, 2018 Dec 07, 2018

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

TOPICS
Scripting
4.9K
Translate
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 , Dec 07, 2018 Dec 07, 2018

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

...
Translate
Contributor ,
Dec 07, 2018 Dec 07, 2018

you want to change character style name from "Bullet Bold Subhead" to: "Font Bold"

Translate
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
Advocate ,
Dec 07, 2018 Dec 07, 2018

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.

Translate
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
Guest
Dec 07, 2018 Dec 07, 2018

Hi,

I need to change the "Apply Style:" to another style. I have uploaded a pic to explain this better.

Thanks, Bren

Translate
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
Guest
Dec 07, 2018 Dec 07, 2018

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

Paragraph Style.png

Translate
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
Advocate ,
Dec 07, 2018 Dec 07, 2018

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?

Bildschirmfoto 2018-12-07 um 11.51.41.png

Translate
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
Guest
Dec 07, 2018 Dec 07, 2018

Hi, yes that's what I need the script to do, this is for thousands of pages so a big ask manually

Translate
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
Advocate ,
Dec 07, 2018 Dec 07, 2018

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.

Bildschirmfoto 2018-12-07 um 11.54.54.png

Translate
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
Guest
Dec 07, 2018 Dec 07, 2018

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.

Translate
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
Advocate ,
Dec 07, 2018 Dec 07, 2018

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

Translate
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 ,
Dec 07, 2018 Dec 07, 2018

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

Translate
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
Guest
Dec 07, 2018 Dec 07, 2018
LATEST

Thank you so much Manan that has worked perfectly, no adjustments or problems.

Very thankful, Bren

Translate
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