5 Replies Latest reply on Apr 29, 2008 1:34 AM by (Dmitry1776)

    why pages arn't being deleting

    Level 1
      I have these lines:

      myPageNum = myStory.Item(1).Parent ' page under cursor
      cntPs = myDoc.Pages.Count 'total amount of pages
      myRange = Array(myPageNum + 1, cntPs)
      myDoc.Pages.ItemByRange(myRange).Delete 'doesn't work
      myDoc.Page.Item(myPageNum).Delete 'doesn't work

      myDoc.Pages.ItemByRange(myPageNum + 1, cntPs).Delete 'doesn't work
      For i = myPageNum + 1 To cntPs 'doesn't work

      but example from this forum does work:

      Set myStory = MyInd.Selection.Item(1).Parent 'Story
      Set myLastTF = myStory.InsertionPoints.Item(-1).ParentTextFrames.Item(1)
      Set myLastPage = myLastTF.Parent
      Do While myDoc.Pages.Item(-1).ID <> myLastPage.ID

      So why it is?
      And can i delete pages by range (to save time, cause looping work is take some seconds)?

        • 1. Re: why pages arn't being deleting
          Level 1
          Hi Dmitry1776,

          You should be using the '.remove' command.

          For example:

          myPages= app.documents[0].pages; //can be used for spreads as well.
          for (var j = myPages.length - 1; j >= 0; j--){
          //add some conditions here.

          Or if you want to remove groups via the script label use the line below. However, I can't get it to work on text frames using the script label though (maybe I should try delete lol.);


          • 2. Re: why pages arn't being deleting
            Level 1
            Yes, it [myPages[j].remove()] works a little bit faster, but i cant believe, that there is not any method for working with range of pages.
            Now manual removing is FASTER, then by script!!! (that is absolute nonsens).

            on line
            b Call myDoc.Pages.ItemByRange(myRange).Delete

            VBS says "Argument not optional".
            • 3. Re: why pages arn't being deleting
              Level 1
              Have you tried:

              Call myDoc.Pages.ItemByRange(myRange).Remove

              I've just checked that this works on a test document:


              but that's JavaScript.

              • 4. Re: why pages arn't being deleting
                Level 1
                Hi Dave,

                I have a snippet of a script below that uses 'itemByRange' and it works well. I don't know if it's faster though because it still deletes one page at a time in sequence.

                function assessSize(){
                var myStories = myDoc.stories;
                var myPage = myDoc.pages;
                if (myGroup = myDoc.groups.item("BP_Front")){
                for (var j = myStories.length - 1; j >= 0; j--){
                if (myStories[j].contents == "2"){
                }else if(myStories[j].contents == 'and so on....'

                But still, if your doing thousands (like I do) then automating through script is the only way to go for speed and accuracy. Dmitry1776 I don't see how doing things manually could be faster.

                • 5. Re: why pages arn't being deleting
                  Level 1
                  Manual pages removing looks like this:
                  In pages palette select by mouse button (with Shift key) needed range of pages and click "trash". It takes from 1 to 3 sec (no matter, how many pages are being deleted).

                  About JS - could you translate (correct) this into JS
                  What i have now:

                  var myDoc = app.ActiveDocument

                  var myInsertionPoint = app.Selection.Item(0);
                  var myStory = myInsertionPoint.ParentTextFrames;
                  var myPage1 = MyInd.ActiveWindow.ActivePage;
                  var myPage = myStory.Item(0).Parent;

                  var cntPs = myDoc.Pages.Count; //total amount of pages
                  var myRange = Array(myPage1 + 1, cntPs);
                  Call myDoc.Pages.ItemByRange(myRange).Remove();

                  this code all time says about errors and doesn't work :((