2 Replies Latest reply on Dec 23, 2015 1:09 AM by K159

    [JS] How to control the scroll bar of the document?

    K159 Level 1

       

      Hi.

       

      I would like to the scroll bar move to a position I want to.

       

      I could not find that I want in the "app.layoutWindow[0]".

       

      Any Ideas?

       

      Thanks.

        • 1. Re: [JS] How to control the scroll bar of the document?
          Laubender Adobe Community Professional & MVP

          Ideas?


          This one:

          Add a helper element, could be a rectangle, to the center of the window you like to see after scrolling.

          Store your current zoom value.

          Select the helper element.

          Change the zoom value to zoom in.

          Change the zoom value to your original value (or your intended value).

          Remove the helper element.

           

          Caveats:

          Some positions will not work as expected, because of limitations in the size of the pasteboard.

          Especially if the center of the resulting "view port" should be on the pasteboard.

           

          Some code; just an example, that should be adapted to your needs:

           

          var doc = app.documents[0];
          var layoutWindow = doc.layoutWindows[0];
          
          // Find a better way to determine the right position.
          // For now the helper rectangle will be positioned on that page.
          var page = layoutWindow.activePage;
          
          var currentZoomPercentage = layoutWindow.zoomPercentage;
          var currentZeroPoint = doc.zeroPoint;
          var viewPreferencesOfDoc = doc.viewPreferences.properties;
          
          doc.viewPreferences.properties =
          {
              rulerOrigin : RulerOrigin.PAGE_ORIGIN,
              horizontalMeasurementUnits : MeasurementUnits.MILLIMETERS,
              verticalMeasurementUnits : MeasurementUnits.MILLIMETERS
             
          };
          
          doc.zeroPoint = [0,0];
          
          // Note: You could work with the bounds of the page to determine a relative position to the page like:
          // Center of quadrant 3 of the page etc.pp.
          
          // A square 2 x 2 millimeters is added and selected:
          var helperRectangle = page.rectangles.add({geometricBounds : [170,130,172,132]});
          doc.select(helperRectangle);
          
          // Changing the zoom percentage will zoom in to the selected object:
          // Maybe I found a bug here, the value must not exceed 2000, anything above will throw an error.
          // Tested with InDesign CC 2015.2 v11.2.0.99 on Mac OSX (German)
          layoutWindow.zoomPercentage = 2000;
          
          // Zoom out again to the original value:
          layoutWindow.zoomPercentage = currentZoomPercentage;
          
          // Tidy up a bit:
          // Remove the helper:
          helperRectangle.remove();
          // Reset the view preferences and the zero point:
          doc.viewPreferences.properties = viewPreferencesOfDoc;
          doc.zeroPoint = currentZeroPoint;
          

           

          Uwe

          • 2. Re: [JS] How to control the scroll bar of the document?
            K159 Level 1

            It works perfectly.

            Thank you very mach.