You must be logged in to post Login

Search Forums:


 






Removing Paragraph styles

UserPost

3:31 pm
January 25, 2012


jessereko

Member

posts 21

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?

4:33 pm
January 25, 2012


Jongware

Member

posts 764

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;
}


6:16 pm
January 26, 2012


jessereko

Member

posts 21

Post edited 6:23 pm – January 26, 2012 by jessereko


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.