7 Replies Latest reply on Apr 24, 2008 10:24 AM by (Christopher_Dick)

    Delete/Replace old Paragraph and Character Styles

      Hi all,

      I was wondering if this is something can could be scripted...

      I've recently switched our company from Quark to InDesign.
      I've also created a copy style structure using Paragraph and Character styles. Something we weren't doing in Quark, and if it was done, it was done badly.

      In our more Important files I made sure before converting to InDesign to Delete all the old useless Quark styles, since we have a new structure now.

      But Quarks styles I'm finding are like a bad penny, they're slowly creeping back into some of our "clean files" from all the left over Quark files that get converted on a needed basis. With these styles being missed, before conversion.

      I have a list and a "master" InDesign document where all the styles were made, and can be easily imported into a new document. But after looking at a list of styles for a while, it's hard to detect right away if something else snuck back in.

      I'd like to try an automate this,...

      where I could run a Script, it would look through the list of Scripts that are suppose to be there, see the ones that aren't, and delete or give me the option to replace with the right ones.
      Even the darn "Normal" one that keeps showing up from Word, etc...

      with out me doing this one-by-one and referring to my list each time. (even though I almost know it by heart now)

      Is this even possible?

      Thanks for your help!!!

      Christopher
        • 1. Re: Delete/Replace old Paragraph and Character Styles
          Level 1
          hi Christopher,

          for PC or for MAC ??

          robin

          --
          www.adobescripts.com
          • 3. Re: Delete/Replace old Paragraph and Character Styles
            Peter Kahrel Adobe Community Professional & MVP
            The script below is a longwinded way of saying "if a style in document x doesn't occur in document y, then try to add an underscore to the beginning of that style's name". With their names prefixed with an underscores you can easily pick out the spurious styles.

            Just change master.indd and check.indd to the names you use, and make sure that both documents are open.

            Peter

            #target indesign

            master = app.documents.item ('master.indd');
            check = app.documents.item ('check.indd');

            try
            {
            master_stylenames = '#' + master.paragraphStyles.everyItem().name.join('#') + '#';
            check_stylenames = check.paragraphStyles.everyItem().name;
            }
            catch(_)
            {
            alert ("Something's wrong--make sure the documents are open.");
            exit()
            }

            for (i = 0; i < check_stylenames.length; i++)
            if (master_stylenames.indexOf ('#'+check_stylenames[i]+'#') < 0)
            try
            {
            check.paragraphStyles.item (check_stylenames[i]).name =
            '_' + check.paragraphStyles.item (check_stylenames[i]).name
            }
            catch(_){}
            • 4. Re: Delete/Replace old Paragraph and Character Styles
              Tom Tomasko Level 1
              Hello,

              I'm wondering if someone could take a look at the posting from a few days ago that asks nearly the same question. The posting is called "Need to compare styles between two documents."

              The difference is that I do not want to have two documents open, a master document and a check document with the "legal" styles in it. I would simply like to check to see if the master document has any extra styles in it as compared to a list in an array.

              The script in the posting does work if one checks simple lists in arrays against each other. But it does not work when using the Styles.everyItem().name method.

              Thanks for the help.

              Tom
              • 5. Re: Delete/Replace old Paragraph and Character Styles
                Peter Kahrel Adobe Community Professional & MVP
                Tom,

                See at your original post.

                Peter
                • 6. Re: Delete/Replace old Paragraph and Character Styles
                  Level 1
                  Hi All,

                  I just got back to this project

                  ok, so I have this script working

                  //Call up active document and create array of Paragraph Styles in the active document. Second array is a list of the only Paragraph Styles that should be in the document.
                  var myDoc = app.activeDocument;
                  var docParagraphStyles = document.paragraphStyles.everyItem().name;
                  var legalParagraphStyles = new Array("BigBook-Body Copy", "BigBook-Line listings", "LineListing_CTA/*Note", "Line Listing Headers", "BigBook-DS Header", "BigBook-ES Header", "BigBook-FS Header", "BigBook-FU Header", "BigBook-HE Header", "BigBook-SL Header", "BigBook-Education Header", "BigBook-HEADLINE DS", "BigBook-HEADLINE ES", "BigBook-HEADLINE FS", "BigBook-HEADLINE FU", "BigBook-HEADLINE HE", "BigBook-HEADLINE Education", "Flyer-Body Copy", "Flyer-Body Copy-Bold-", "Flyer-Body Copy-Bold:", "Flyer-Body Copy-Bold points", "Flyer-Line listings", "Flyer-DS Header", "Flyer-ES Header", "Flyer-FS Header", "Flyer-FU Header", "Flyer-HE Header", "Flyer-SL Header", "SL-DS Header", "SL-ES Header", "SL-FS Header", "SL-FU Header", "SL-HE Header", "SL-Education Header", "SL-HEADLINE DS", "SL-HEADLINE ES", "SL-HEADLINE HE", "SL-HEADLINE FS", "SL-HEADLINE FU", "SL-HEADLINE Education", "Product Captions-DS", "Product Captions-ES", "Product Captions-FS", "Product Captions-FU", "Product Captions-HE", "Product Captions-SL", "Product Captions-Education", "Bob_Burster", "Product_Expertise_#'s");
                  //Turn the arrays into strings with '~' separators
                  var arrstring1 = '~' + docParagraphStyles.join('~');
                  var arrstring2 = '~' + legalParagraphStyles.join('~');
                  //Compares the words in both strings. If any are the same, deletes them from both strings. Creates final string with only the unique words.
                  for (var i = 0; i < docParagraphStyles.length; i++)
                    {
                    var replacestring = '~' + docParagraphStyles[i];
                    if (arrstring2.indexOf(replacestring) > -1)
                      {
                      arrstring1 = arrstring1.replace(replacestring, '');
                  arrstring2 = arrstring2.replace(replacestring, '');
                      }
                    }
                  var arrstring = (arrstring1 +arrstring2).substr(1);
                  var illegalStyles = arrstring.split('~');
                  //First alert shows Paragraph Styles in active document.
                  //Second alert is a list of the only Paragraph Styles that sould be in the document.
                  //Third alert should show the extra Paragraph Styles that should not be in the document.
                  Window.alert(docParagraphStyles);
                  Window.alert(legalParagraphStyles);
                  Window.alert(illegalStyles);

                  And this one,...

                  #target indesign

                  var myDoc = app.activeDocument;
                  master = app.documents.item ('Copy_Block_Formating.indd');
                  check = app.activeDocument;

                  try
                  {
                  master_stylenames = '#' + master.paragraphStyles.everyItem().name.join('#') + '#';
                  check_stylenames = check.paragraphStyles.everyItem().name;
                  }
                  catch(_)
                  {
                  alert ("Something's wrong--make sure the documents are open.");
                  exit()
                  }

                  for (i = 0; i < check_stylenames.length; i++)
                  if (master_stylenames.indexOf ('#'+check_stylenames[i]+'#') < 0)
                  try
                  {
                  check.paragraphStyles.item (check_stylenames[i]).name =
                  '_' + check.paragraphStyles.item (check_stylenames[i]).name
                  }
                  catch(_){}

                  Now is there a way I can put the Array from the first one, and combine it with the second one to have it search a document (without the original being open) and rename the bad styles with an underscore all at once?

                  One more thing, how do you get the first Script to look inside Style Folders for scripts?

                  Thanks!!!

                  Christopher
                  • 7. Re: Delete/Replace old Paragraph and Character Styles
                    Level 1
                    Sorry same Mac OS but now in CS3