Removing Paragraph styles
Learn / Forums / InDesign Add-ons (Scripts, Scripting, and Plug-ins) / Removing Paragraph styles
- This topic has 3 replies, 3 voices, and was last updated 6 years ago by Luette Arrowsmith.
-
AuthorPosts
-
-
January 25, 2012 at 3:31 pm #61544Jesse RekoMember
Hello, I've recently found this bit of code that finds character styles by name, replaces them and deletes the old style
var myDocument = app.activeDocument;
if (myDocument.characterStyles.item(“Title”) != null) {
if (myDocument.characterStyleGroups.item(“Catalog Styles”). characterStyles.item(“title”) != null) {
myDocument.characterStyles.item(“Title”).remove(myDocument.characterStyleGroups.item(“Catalog Styles”). characterStyles.item(“title”));
I was wondering if anyone could think of a way to define a list of the styles you wouldn't want deleted and delete everything else?
-
January 25, 2012 at 4:33 pm #61547Theunis De JongMember
Here is a script that will relentlessly remove all except in the list “keepThese”. Your example script replaces it with another, this one does not (so you might want to make sure this is what you meant).
Note that it solely tests the name of each character style, not if and where it is inside any style group. If you have two styles named “test” in two different groups, both will remain.
// Put your “keep” style names in here:
var keepThese = [ “test”, test2 ];charStyles = app.activeDocument.allCharacterStyles;
for (i=charStyles.length-1; i>=1; i=i-1)
{
if (!inList (keepThese, charStyles[i].name))
charStyles[i].remove();
}function inList (list, item)
{
var i;
for (i=0; i<list.length; i++)
if (list[i] == item)
return true;
return false;
} -
January 26, 2012 at 6:16 pm #61559Jesse RekoMember
You are always so fast! Thanks for helping once again,
I think probably I use my stuff to do the conversion first and then run your to kill the other ones.
Our style sheets have been getting really overgrown over the past few years due to ~40 people, mostly not designers using assets that later come into our documents and bring their styles with them so its helpful to be able to run this often when there are changes in the catalog mid production.
Thanks again.
-
April 12, 2018 at 5:53 am #103066Luette ArrowsmithMember
is there a way to remove multiple styles? My document when through an addin to make a pagemaker file into InDesign but it created 200 plus styles. Would rather not do each one by hand.
-
-
AuthorPosts
- You must be logged in to reply to this topic.