Script to rename all Paragraph styles
Learn / Forums / InDesign Add-ons (Scripts, Scripting, and Plug-ins) / Script to rename all Paragraph styles
Tagged: #paragraphstylerename
- This topic has 18 replies, 8 voices, and was last updated 5 years, 6 months ago by Kai Rübsamen.
-
AuthorPosts
-
-
August 3, 2016 at 7:40 am #87055Cindy KelleyParticipant
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 -
August 3, 2016 at 12:29 pm #87068Kai RübsamenMember
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
-
August 23, 2017 at 6:33 am #97017Masood AhmadParticipant
@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.
-
August 25, 2017 at 5:33 am #97065Kai RübsamenMember
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?
-
-
August 3, 2016 at 12:38 pm #87069Cindy KelleyParticipant
OMG! You have saved me so much time.
xoxo -
August 3, 2016 at 12:42 pm #87070Cindy KelleyParticipant
at the sake of being greedy, how about for Character Styles as well? ;)
-
August 3, 2016 at 1:18 pm #87072Kai RübsamenMember
Try it by yourself! Since this is a easy script, it should not be so difficult to change paragraph to character ;-)
-
September 20, 2018 at 1:11 pm #110498Rance ShepstoneMember
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?
-
September 20, 2018 at 10:16 pm #110499Kai RübsamenMember
No, not without seeing a example. So please provide a .idml and some comments, what those few lines should change.
-
September 21, 2018 at 7:35 am #110500Rance ShepstoneMember
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.
-
September 21, 2018 at 8:52 am #110501Kai RübsamenMember
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.
-
-
August 3, 2016 at 1:30 pm #87073Cindy KelleyParticipant
I did. I replaced
allParaStyles
withallCharStyles
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. :)
-
August 3, 2016 at 1:35 pm #87074Cindy KelleyParticipant
Got it :)
I forgot to change that first line.Thanks for making me think.
-
August 3, 2016 at 1:42 pm #87075Kai RübsamenMember
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 …
-
September 22, 2016 at 1:08 pm #88620Spring LenoxMember
OK. A twist: What if I wanted to swap out all periods and replace with underscores in the name?
-
September 22, 2016 at 1:56 pm #88622Peter KahrelParticipant
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
-
-
September 22, 2016 at 3:48 pm #88625Spring LenoxMember
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.
-
January 15, 2017 at 8:56 am #91253Surendar JakkaMember
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.
-
August 2, 2017 at 6:26 pm #96472Luis Felipe CorullonParticipant
I have my own rename styles script. It works for me.
-
-
AuthorPosts
- You must be logged in to reply to this topic.