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

Converting Nested Styles into Local Character Styles

Participant ,
Feb 25, 2024 Feb 25, 2024

Hello, I am having some problems with paragraph styles (when I export to html or epub) where I use grep style.
To convert grep styles to local character styles

http://in-tools.com/products/scripts/

I use (Apply Nested Style). But here, my extra underlined words on the paragraph are not visible.
Does anyone know another solution? Thanks in advance for your help.

 

TOPICS
Scripting
1.2K
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 2 Correct answers

Community Expert , Mar 01, 2024 Mar 01, 2024

In that case you use this one:

 

(function () {
  
  var indd = app.documents.item(0);

  function applyAsLiteral (gstyle) {
    app.findGrepPreferences.findWhat = gstyle.grepExpression;
    app.changeGrepPreferences.appliedCharacterStyle = gstyle.appliedCharacterStyle;
    indd.changeGrep();
  }

  function grepStyleToNormal (ps) {
    var gstyles = ps.nestedGrepStyles.everyItem().getElements();
    for (var i = 0; i < gstyles.length; i++) {
      if (gstyles[i].name !== 'myChar') {
        app
...
Translate
Community Expert , May 20, 2025 May 20, 2025

The script posted here has two flaws (one fatal): It doesn't deal with overlapping character styles and it doesn't handle based-on styles.

 

I upgraded the script and posted it here:

https://creativepro.com/files/kahrel/indesign/grep-styles-to-local-styles.html

 

Translate
Participant ,
Feb 28, 2024 Feb 28, 2024

I'm not sure I understand your question. Can you provide some more detail about what your desired vs. actual outcome is, and a screenshot?

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
Participant ,
Feb 29, 2024 Feb 29, 2024

Thank you for your interest. I guess I didn't explain it clearly. But @Peter Kahrel saw the problem and helped me find the right answer. Thanks a lot.

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 ,
Feb 29, 2024 Feb 29, 2024

The In-Tools script doesn't deal with GREP styles, that's why it doesn't work for you.

 

Here's a script that converts GREP styles to character styles applied in the document. Be aware though that any character style applied directly will be overridden, and also that GREP styles are additive, i.e. they don't cancel each other out, whereas directly applied character style do cancel each other out: the last character style applied wins.

 

 

(function () {
  
  var indd = app.documents.item(0);

  function applyAsLiteral (gstyle) {
    app.findGrepPreferences.findWhat = gstyle.grepExpression;
    app.changeGrepPreferences.appliedCharacterStyle = gstyle.appliedCharacterStyle;
    indd.changeGrep();
  }

  function grepStyleToNormal (ps) {
    var gstyles = ps.nestedGrepStyles.everyItem().getElements();
    for (var i = 0; i < gstyles.length; i++) {
      applyAsLiteral (gstyles[i]);
    }
    ps.nestedGrepStyles.everyItem().remove();
  }

  app.findGrepPreferences = app.changeGrepPreferences = null;
  var pstyles = indd.allParagraphStyles;
  for (var i = pstyles.length-1; i >= 1; i--) {
    grepStyleToNormal (pstyles[i]);
  }

}());

 

 

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
Participant ,
Feb 29, 2024 Feb 29, 2024

Worked great Peter, thank you very much.

Except for one problem you mentioned. Subsequently applied character styles.
There is a character style called “myChar” which I then applied. How can I proceed if I don’t want this to change? Thank again...

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 ,
Mar 01, 2024 Mar 01, 2024

In that case you use this one:

 

(function () {
  
  var indd = app.documents.item(0);

  function applyAsLiteral (gstyle) {
    app.findGrepPreferences.findWhat = gstyle.grepExpression;
    app.changeGrepPreferences.appliedCharacterStyle = gstyle.appliedCharacterStyle;
    indd.changeGrep();
  }

  function grepStyleToNormal (ps) {
    var gstyles = ps.nestedGrepStyles.everyItem().getElements();
    for (var i = 0; i < gstyles.length; i++) {
      if (gstyles[i].name !== 'myChar') {
        applyAsLiteral (gstyles[i]);
      }
    }
    ps.nestedGrepStyles.everyItem().remove();
  }

  app.findGrepPreferences = app.changeGrepPreferences = null;
  var pstyles = indd.allParagraphStyles;
  for (var i = pstyles.length-1; i >= 1; i--) {
    grepStyleToNormal (pstyles[i]);
  }

}());
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
Participant ,
Mar 01, 2024 Mar 01, 2024

Hi @Peter Kahrel;

It works perfectly, thank you very much, I can do more specific work on this script. 

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 ,
May 20, 2025 May 20, 2025
LATEST

The script posted here has two flaws (one fatal): It doesn't deal with overlapping character styles and it doesn't handle based-on styles.

 

I upgraded the script and posted it here:

https://creativepro.com/files/kahrel/indesign/grep-styles-to-local-styles.html

 

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