3 Replies Latest reply on Jul 1, 2011 6:49 AM by James A L.

    Scroll to Top of Page

    James A L. Level 1

      I am writing a new document script. What do I need to add to get the new document to be scrolled to the top?

       

      Here's the script so far:

       

      var doc = app.documents.add();
      var frm = doc.pages[0].textFrames.add();
      var w = doc.documentPreferences.pageWidth;
      var h = doc.documentPreferences.pageHeight;
      frm.geometricBounds = [.5, .5, h-.5, w-.5];
      frm.contents = "Title";
      frm.paragraphs[0].appliedParagraphStyle = "Title";
      app.activeDocument.layoutWindows[0].zoomPercentage = 250;

       

      I suppose a possible solution would be to enter a line of script that would amount to the same thing as pressing the Page Up key on the keyboard, but I do not know what script would do this.

       

      Any help would be appreciated. Thanks.

        • 1. Re: Scroll to Top of Page
          James A L. Level 1

          Does anyone have a suggestion on this?

           

          Is there some way to script what the scroll bar does?

           

          Or is there some way to script something equivalent to the "Page Up" key on the keyboard?

           

          Thanks again.

          • 2. Re: Scroll to Top of Page
            Muppet Mark Level 5

            There are no view controls in InDesign like there are in Illustrator where you can pass a center point… What you can do however is mimic the behavior of the app itself… Voom will work about an active document selection… So just place a temp box in the area you wish to see on screen, make it selected, zoom to given percentage and remove box. Its not so elegant but possibly the best work about I can think up to do this… Eg:

             

            var doc = app.documents.add();
            
            var frm = doc.pages[0].textFrames.add();
            
            var w = doc.documentPreferences.pageWidth;
            
            var h = doc.documentPreferences.pageHeight;
            
            frm.geometricBounds = [.5, .5, h-.5, w-.5];
            
            frm.contents = "Title";
            
            //frm.paragraphs[0].appliedParagraphStyle = "Title";
            
            var tmp = doc.pages[0].rectangles.add();
            
            tmp.move([0,0]);
            
            tmp.select(SelectionOptions.replaceWith);
            
            app.activeDocument.layoutWindows[0].zoomPercentage = 250;
            
            tmp.remove();
            

            • 3. Re: Scroll to Top of Page
              James A L. Level 1

              Thanks, Muppet Mark, I really appreciate it.

               

              Your script worked. I just adjusted the position of the rectangle a bit to get things centered better. I changed the move line to read:

               

              tmp.move([4.25, 2]);

               

              Then the script works perfectly. Thanks a lot for your help.