Removing Paragraph styles

Viewing 3 reply threads
  • Author
    Posts
    • #61544
      Jesse Reko
      Member

      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?

    • #61547

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

    • #61559
      Jesse Reko
      Member

      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.

    • #103066

      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.

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