Script to rename all Paragraph styles

Learn / Forums / InDesign Add-ons (Scripts, Scripting, and Plug-ins) / Script to rename all Paragraph styles

Viewing 11 reply threads
  • Author
    Posts
    • #87055
      Cindy Kelley
      Participant

      Hi,

      For example, I would like to add “2016” to the beginning of each paragraph style. Is this possible with a script?

      Thanks for any help!
      Cindy

    • #87068

      Hi Cindy,

      yes this is possible:

      var allParaStyles = app.activeDocument.allParagraphStyles;
      
      var before = "2016_";
      
      for (var i = 2; i < allParaStyles.length; i++) {
        var curStyle = allParaStyles[i];
        var curName = curStyle.name;
        if (curName.indexOf(before) == -1) {
          var newName = before + curName;
          curStyle.name = newName;
        }
      }
      

      Kai

      • #97017
        Masood Ahmad
        Participant

        @Kai, Let’s say…
        I group all the Paragraph Styles and named the group as “Styles for ABC”, now I want a script that will pop me to input the Group name (to make changes to) and also pop me for the suffix to rename the para styles with that group.

        This is useful, when I want to duplicate the styles and create new ones with minimal changes.

        Hope you have something in your pockets.

      • #97065

        Hi Masood, I have nothing in my pocket ;-) And I’m not sure, if this is possible, cause if you have more than one group, how should the script know, which group is selected?

    • #87069
      Cindy Kelley
      Participant

      OMG! You have saved me so much time.
      xoxo

    • #87070
      Cindy Kelley
      Participant

      at the sake of being greedy, how about for Character Styles as well? ;)

    • #87072

      Try it by yourself! Since this is a easy script, it should not be so difficult to change paragraph to character ;-)

      • #110498

        Kai, this script is working but only for two groups in my styles. The other styles are unaffected. Do you know why this may be?

      • #110499

        No, not without seeing a example. So please provide a .idml and some comments, what those few lines should change.

      • #110500

        Okay, unfortunately I don’t know how to share an idml on this website. I’m new to using scripts. Somehow I got the script to work once on all styles, but I don’t know how I did it. I thought it worked because I duplicated my style groups, but I can’t get it to work again. I’m also receiving an error message #517 line 10 source: curstyle.Name = newName. Not sure if the error is related or just part of the scripts function.

      • #110501

        You can send me a example to [email protected]. Without seeing the error and a detailed description, what should be your final result, I can’t help you.

    • #87073
      Cindy Kelley
      Participant

      I did. I replaced

      allParaStyles
      with

      allCharStyles

      and

      allCharacterStyles

      yet no go.

      I even opened another script using Character styles and it showed “allCharacterStyles” so I thought that would work but nope.

      But don’t tell me the fix yet. I am going to google and keep trying. :)

    • #87074
      Cindy Kelley
      Participant

      Got it :)
      I forgot to change that first line.

      Thanks for making me think.

    • #87075

      Aha! :) If you are able to read scripts, it is sometimes very easy to make minor changes, e.g. put your text after the para style name …

    • #88620
      Spring Lenox
      Member

      OK. A twist: What if I wanted to swap out all periods and replace with underscores in the name?

      • #88622
        Peter Kahrel
        Participant

        This would do it:

        pstyles = app.documents[0].allParagraphStyles;
        for (i = pstyles.length-1; i > 1; i--) {
          pstyles[i].name = pstyles[i].name.replace(/\./g,'_');
        }

        Peter

    • #88625
      Spring Lenox
      Member

      Thanks, Peter! I’d found the script you did from 2014 PePcon (https://www.kahrel.plus.com/indesign/rename_styles.html). That script removed the periods, so I was trying to dissect the script to figure out where and how to get that underscore in there. You saved me a ton of time.

    • #91253

      I need a script to rename the styles.
      example: i have a style named
      body text 60, Bold 6055, Heading, Title
      I need these to get changed to
      body text 70, Bold 7055, Heading 70, Title 70.

      Can someone please help me to solve this.

    • #96472

      I have my own rename styles script. It works for me.

      https://lf.corullon.com.br/scripts_id_lfc/index_enus.html

Viewing 11 reply threads
  • You must be logged in to reply to this topic.
>