4 Replies Latest reply on Jan 13, 2014 11:55 PM by Mi_D

    Delete All Object Style in documents

    creativejoan0425 Level 1

      I want to delete all object style named "Footer", it can run when I have one Master Page, but if I have a 2nd Master Page Accroding to 1st Master Page, it occur error and CS6 will quit automatically, is it CS6 bugs or my script is wrong? anyone can help?

       

      question.jpg

      function ClearAllFooter(){
      app.findObjectPreferences = app.changeObjectPreferences = null;
      app.findChangeObjectOptions.includeFootnotes = true;
      app.findChangeObjectOptions.includeHiddenLayers = true;
      app.findChangeObjectOptions.includeLockedLayersForFind = true;
      app.findChangeObjectOptions.includeLockedStoriesForFind = true;
      app.findChangeObjectOptions.includeMasterPages = true;
      var oStyle = app.activeDocument.objectStyles.item("Footer");
      app.findObjectPreferences.appliedObjectStyles = oStyle;
      var found = app.findObject();
      app.findObjectPreferences = app.changeObjectPreferences = null;
      for ( var f = 0; f < found.length; f++ ) {
          found[f].remove();

      }
      }
      ClearAllFooter();

        • 1. Re: Delete All Object Style in documents
          Kasyan Servetsky Level 5

          When you remove objects, you should move backwards, like so:

          for (var f = found.length-1; f >= 0; f--) {

           

          Alternatively, you can set the reverseOrder parameter to true:

          var found = app.findObject(true);

          app.findObjectPreferences = app.changeObjectPreferences = null;

          for ( var f = 0; f < found.length; f++ ) {

          • 2. Re: Delete All Object Style in documents
            creativejoan0425 Level 1

            I try to change the script, it also will quit the indesign

             

            function ClearAllFooter(){

            app.findObjectPreferences = app.changeObjectPreferences = null;

            app.findChangeObjectOptions.includeFootnotes = true;

            app.findChangeObjectOptions.includeHiddenLayers = true;

            app.findChangeObjectOptions.includeLockedLayersForFind = true;

            app.findChangeObjectOptions.includeLockedStoriesForFind = true;

            app.findChangeObjectOptions.includeMasterPages = true;

            var oStyle = app.activeDocument.objectStyles.item("Footer");

            app.findObjectPreferences.appliedObjectStyles = oStyle;

            var found = app.findObject(true);

            app.findObjectPreferences = app.changeObjectPreferences = null;

            for (var f = found.length-1; f >= 0; f--)  {

                found[f].remove();

            }

            }

            ClearAllFooter();

             

            version 2:

             

            function ClearAllFooter(){

            app.findObjectPreferences = app.changeObjectPreferences = null;

            app.findChangeObjectOptions.includeFootnotes = true;

            app.findChangeObjectOptions.includeHiddenLayers = true;

            app.findChangeObjectOptions.includeLockedLayersForFind = true;

            app.findChangeObjectOptions.includeLockedStoriesForFind = true;

            app.findChangeObjectOptions.includeMasterPages = true;

            var oStyle = app.activeDocument.objectStyles.item("Footer");

            app.findObjectPreferences.appliedObjectStyles = oStyle;

            var found = app.findObject();

            app.findObjectPreferences = app.changeObjectPreferences = null;

            for (var f = found.length-1; f >= 0; f--) {

                found[f].remove();

            }

            }

            ClearAllFooter();

             

            version 3:

             

            function ClearAllFooter(){

            app.findObjectPreferences = app.changeObjectPreferences = null;

            app.findChangeObjectOptions.includeFootnotes = true;

            app.findChangeObjectOptions.includeHiddenLayers = true;

            app.findChangeObjectOptions.includeLockedLayersForFind = true;

            app.findChangeObjectOptions.includeLockedStoriesForFind = true;

            app.findChangeObjectOptions.includeMasterPages = true;

            var oStyle = app.activeDocument.objectStyles.item("Footer");

            app.findObjectPreferences.appliedObjectStyles = oStyle;

            var found = app.findObject(true);

            app.findObjectPreferences = app.changeObjectPreferences = null;

            for ( var f = 0; f < found.length; f++ ) {

                found[f].remove();

            }

            }

            ClearAllFooter();

            • 3. Re: Delete All Object Style in documents
              creativejoan0425 Level 1

              When B Master not According to A Master, and put the footer inside both A and B, it ok, not error, it is still hv something I need to write?

              • 4. Re: Delete All Object Style in documents
                Mi_D Level 3

                try below code

                 

                var myDoc = app.activeDocument;

                app.findObjectPreferences = app.changeObjectPreferences = null;

                app.findChangeObjectOptions.includeFootnotes = true;

                app.findChangeObjectOptions.includeHiddenLayers = true;

                app.findChangeObjectOptions.includeLockedLayersForFind = true;

                app.findChangeObjectOptions.includeLockedStoriesForFind = true;

                app.findChangeObjectOptions.includeMasterPages = true;

                var oStyle = app.activeDocument.objectStyles.item("Footer");

                app.findObjectPreferences.appliedObjectStyles = oStyle;

                var found = app.findObject(true);

                for ( var f = 0; f < found.length; f++ ) {

                    found[f].appliedObjectStyle = myDoc.objectStyles.item (0);//replace footer style with none

                }

                app.findObjectPreferences = app.changeObjectPreferences = null;

                 

                Mi_D