4 Replies Latest reply on Sep 25, 2014 4:58 AM by amandasgarden

    Remove style groups

    amandasgarden Level 1

      Hi! I have about 400 Indesign documents that all have 29 paragraph style gruops that I no longer need. Is there a way to remove these, along with their content, with a script? All style groups have a corresponding character style group that would be nice if it were to be removed also.

       

      Bests regards,

      Mikael Wiik

        • 1. Re: Remove style groups
          Sajeev Sridharan Level 4

          Try this,

           

          var myInddFileList = File.openDialog ("Choose the InDesign files to remove Style Group..." , "*.indd", true);
          for (var f = 0; f < myInddFileList.length; f++)
          {
              var myInddFile = app.open(File(myInddFileList[f]));
              var myDoc = app.activeDocument;
          
              //Deleting the content of Paragraph Style Group
              for(i=0; i<myDoc.paragraphStyleGroups.length; i++)
              {
                  for(j=0; j<myDoc.paragraphStyleGroups[i].paragraphStyles.length; j++)
                  {
                      app.findGrepPreferences = app.changeGrepPreferences = null;
                      app.findGrepPreferences.findWhat = ".+";
                      app.findGrepPreferences.appliedParagraphStyle = myDoc.paragraphStyleGroups.itemByName(myDoc.paragraphStyleGroups[i].name).paragraphStyles.item(myDoc.paragraphStyleGroups[i].paragraphStyles[j].name);
                      app.changeGrepPreferences.changeTo  = "";//deleting the text
                      app.activeDocument.changeGrep();
                      app.findGrepPreferences = app.changeGrepPreferences = null;
                  }
              }
          
          
              //Deleting the content of Character Style Group
              for(i=0; i<myDoc.characterStyleGroups.length; i++)
              {
                  for(j=0; j<myDoc.characterStyleGroups[i].characterStyles.length; j++)
                  {
                      app.findGrepPreferences = app.changeGrepPreferences = null;
                      app.findGrepPreferences.findWhat = ".+";
                      app.findGrepPreferences.appliedCharacterStyle = myDoc.characterStyleGroups.itemByName(myDoc.characterStyleGroups[i].name).characterStyles.item(myDoc.characterStyleGroups[i].characterStyles[j].name);
                      app.changeGrepPreferences.changeTo  = "";//deleting the text
                      app.activeDocument.changeGrep();
                      app.findGrepPreferences = app.changeGrepPreferences = null;
                  }
              }
          
          
              //Deleting the Paragraph Style and Character Style Group
              myDoc.paragraphStyleGroups.everyItem().remove(); 
              myDoc.characterStyleGroups.everyItem().remove(); 
              myDoc.close(SaveOptions.YES);
          }
          
          
          
          

           

          Vandy

          • 2. Re: Remove style groups
            amandasgarden Level 1

            Is there a way to specify which style groups that will be deleted. I was unclear in my previous post. There are 29 groups that are no longer needed, but the indesign document contains a lot more groups.

            • 3. Re: Re: Remove style groups
              Sajeev Sridharan Level 4

              Try this,

               

              var myInddFileList = File.openDialog ("Choose the InDesign files to remove Paragraph Style Group..." , "*.indd", true);
              for (var f = 0; f < myInddFileList.length; f++)
              {
                  var myInddFile = app.open(File(myInddFileList[f]));
                  var myDoc = app.activeDocument; 
                  var myParaGroup = ["paragroup1", "paragroup2"]; //mention your paragraph style group name here
                  var myCharGroup = ["chargroup1", "chargroup2"]; //mention your character style group name here
              
              
                  //Deleting the content of Paragraph Style Group
                  for(i=0; i<myDoc.paragraphStyleGroups.length; i++)
                  {
                      for(j=0; j<myDoc.paragraphStyleGroups[i].paragraphStyles.length; j++)
                      {
                          for(k=0; k<myParaGroup.length; k++)
                          {
                              if(myDoc.paragraphStyleGroups[i].name==myParaGroup[k])
                              {
                                  app.findGrepPreferences = app.changeGrepPreferences = null;
                                  app.findGrepPreferences.findWhat = ".+";
                                  app.findGrepPreferences.appliedParagraphStyle = myDoc.paragraphStyleGroups.itemByName(myDoc.paragraphStyleGroups[i].name).paragraphStyles.item(myDoc.paragraphStyleGroups[i].paragraphStyles[j].name);
                                  app.changeGrepPreferences.changeTo  = "";//deleting the text
                                  app.activeDocument.changeGrep();
                                  app.findGrepPreferences = app.changeGrepPreferences = null;
                                  app.activeDocument.paragraphStyleGroups.itemByName(myParaGroup[k]).remove();
                              }
                          }
                      }
                  }
              
              
                  //Deleting the content of Character Style Group
                  for(i=0; i<myDoc.characterStyleGroups.length; i++)
                  {
                      for(j=0; j<myDoc.characterStyleGroups[i].characterStyles.length; j++)
                      {
                          for(k=0; k<myCharGroup.length; k++)
                          {
                              if(myDoc.characterStyleGroups[i].name==myCharGroup[k])
                              {
                                  app.findGrepPreferences = app.changeGrepPreferences = null;
                                  app.findGrepPreferences.findWhat = ".+";
                                  app.findGrepPreferences.appliedCharacterStyle = myDoc.characterStyleGroups.itemByName(myDoc.characterStyleGroups[i].name).characterStyles.item(myDoc.characterStyleGroups[i].characterStyles[j].name);
                                  app.changeGrepPreferences.changeTo  = "";//deleting the text
                                  app.activeDocument.changeGrep();
                                  app.findGrepPreferences = app.changeGrepPreferences = null;
                                  app.activeDocument.characterStyleGroups.itemByName(myCharGroup[k]).remove();
                              }
                          }
                      }
                  }
                  myDoc.close(SaveOptions.YES);
              }
              

               

               

              Vandy

              • 4. Re: Re: Remove style groups
                amandasgarden Level 1

                It worked like a charm! Thank you very much, you have saved med many hours of work!

                /Mikael Wiik