6 Replies Latest reply on Jul 26, 2014 6:10 PM by zuhair777

    A little change is required in the script, please help.

    zuhair777 Level 1

      I am using a script named as <Zoom to Width> that I found on web. This script does two jobs

      (1) zoom to a specific percentage

      (2) and center the page horizontally as well vertically at that zoom level.

       

      I have changed the zoom value to 170% in it. Now the problem is that when script center the page at 170% it shows the middle of the page (horizontal as well as vertical). I need horizontal center but not vertical center of page, so I have to move to the top of page by scrolling or by moving cursor. I want a little change in it that vertically top of the page should appear instead of the middle of page i.e.

      I want 170% zoom + horizontal page center + vertical page top.

      I would appreciate any help. I am on Windows 64bit. Here is the script

       

      //DESCRIPTION: Zooms to the width of currently selected object or the current page. http://www.in-tools.com

      ZoomToWidth();

      function ZoomToWidth(){

          var kAppVersion=parseFloat(app.version);

          try{

              if(File.fs == "Macintosh"){var isMac = true}

              else{var isMac = false}

              if(kAppVersion>=6 && app.generalPreferences.useApplicationFrame){

                  var usesApplicationFrame = true;

                  }

              else{var usesApplicationFrame = false}

              var sel=app.selection[0];

              var window = app.activeWindow;

              if(! (window instanceof LayoutWindow) ){return}

              var doc = app.documents[0];

              var horizViewPrefs = doc.viewPreferences.horizontalMeasurementUnits;

              doc.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.points;

              var theWidth = doc.documentPreferences.pageWidth;

              var theHeight = doc.documentPreferences.pageHeight;

              var theSpread = window.activeSpread;

              var pagesLength = theSpread.pages.length;

              if(isMac){

                  var windowWidth = window.bounds[3]-window.bounds[1]-35;

                  if(usesApplicationFrame){

                      window.zoom(ZoomOptions.fitSpread);

                      var spreadZoom = window.zoomPercentage;

                      windowWidth = (spreadZoom/170)*(theWidth*pagesLength);

                      }

                  }

              else{

                  var windowWidth = window.bounds[3]-window.bounds[1]-50;

                  if(usesApplicationFrame){//|| pagesLength>1 || theWidth>theHeight

                      window.zoom(ZoomOptions.fitSpread);

                      var spreadZoom = window.zoomPercentage;

                      windowWidth = (spreadZoom/170)*(theWidth*pagesLength);

                      }

                  }

              if(sel && (sel.hasOwnProperty("parentTextFrames") || sel.hasOwnProperty("visibleBounds")) ){

                  if(sel.hasOwnProperty("parentTextFrames")){

                      var textFrame = sel.parentTextFrames[0];

                      var frameBounds = textFrame.visibleBounds;

                      app.select(sel.parentTextFrames[0]);

                      }

                  else{frameBounds = sel.visibleBounds}

                  theWidth = frameBounds[3]-frameBounds[1];

                  }

              else{window.zoom(ZoomOptions.fitPage)}

              window.zoomPercentage = (windowWidth/theWidth)*170;

              doc.viewPreferences.horizontalMeasurementUnits = horizViewPrefs;

              app.select(sel);

              }

          catch(e){}

          }

        • 1. Re: A little change is required in the script, please help.
          Jump_Over Level 5

          Hi,

          Basically your function is zooming base to width (selected object or window) so instead of modifying I suggest to create a new a "base to scale" function.

          To keep top window content shown after scaling one can use a trick and select temporalily created object in a center (remove it after), so:

          function zoomToScale(myScale) {
            if (isNaN(myScale) || myScale > 4000 || myScale < 4) myScale = 100;
            var 
            window = app.activeWindow,
            mDoc = app.activeDocument,
            mZeroPoint = mDoc.zeroPoint,
            mHorizViewPrefs = mDoc.viewPreferences.horizontalMeasurementUnits,
            mActiveSpread = window.activeSpread,
            mSpreadPages = mActiveSpread.pages.length,
            mWidth, theRec, mTopCenter;
          
            mDoc.zeroPoint = [0,0];
            mDoc.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.points;
          
            mWidth = mDoc.documentPreferences.pageWidth;
            theRec = mActiveSpread.rectangles.add();
            mTopCenter = mWidth*mSpreadPages / 2;
          
            theRec.move(undefined,[mTopCenter,0]);
          
            window.zoom(ZoomOptions.fitSpread);
            window.zoomPercentage = myScale;
            app.selection = theRec;
            theRec.remove();  
            mDoc.zeroPoint = mZeroPoint;
            mDoc.viewPreferences.horizontalMeasurementUnits = mHorizViewPrefs;
          }
          

           

          call it i.e. this way:

          zoomToScale(170);
          

           

          myScale is reset to 100 if it is out of range or is not a number

           

          Jarek

          • 2. Re: A little change is required in the script, please help.
            zuhair777 Level 1

            Thank you for your kind reply. Apologies for I have no knowledge of scripts. I do not know how to apply it. Here is what I did.

            I created a txt file, copy and pasted your above lines, saved it, change the extension to jsx and copied it to the scripts panel folder. It appeared in the scripts list in InDesign, I applied it but nothing happened. Then I changed the first line according to your last line i.e.

             

            zoomToScale(170);


            but now it shows error in InDesign.


            • 3. Re: A little change is required in the script, please help.
              Jump_Over Level 5

              Hi,

               

              Tell me more about an error

              Jarek

              • 4. Re: A little change is required in the script, please help.
                zuhair777 Level 1

                I did few more tries and I pasted your last line

                zoomToScale(170);

                on the top of your script. Now the script is working without any error but it centers the spread horizontally while I want the centre of active page.

                • 5. Re: Re: A little change is required in the script, please help.
                  Jump_Over Level 5

                  Hi,

                   

                  Some modifications:

                  zoomToScale( Number(prompt("Set a zoom scale (5-4000)")) );
                  
                  function zoomToScale(myScale) { 
                    if (isNaN(myScale) || myScale > 4000 || myScale < 5) myScale = 100; 
                    var 
                    window = app.activeWindow, 
                    mDoc = app.activeDocument, 
                    mZeroPoint = mDoc.zeroPoint, 
                    mHorizViewPrefs = mDoc.viewPreferences.horizontalMeasurementUnits, 
                    mActivePage = window.activePage, 
                    theRec, mTopCenter; 
                  
                    mDoc.zeroPoint = [0,0]; 
                    mDoc.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.points; 
                  
                    theRec = mActivePage.rectangles.add(); 
                    mTopCenter = (mActivePage.bounds[3] - mActivePage.bounds[1]) / 2; 
                  
                    theRec.move(undefined,[mTopCenter,0]); 
                  
                    window.zoom(ZoomOptions.fitSpread); 
                    window.zoomPercentage = myScale; 
                    app.selection = theRec; 
                    theRec.remove();   
                    mDoc.zeroPoint = mZeroPoint; 
                    mDoc.viewPreferences.horizontalMeasurementUnits = mHorizViewPrefs; 
                  }
                  

                   

                  Jarek

                  • 6. Re: A little change is required in the script, please help.
                    zuhair777 Level 1

                    Thank you so much now it is working correctly.

                     

                    Can you explain what change is done by command <Set Measure Units> in this script? Does it changes my measuring units?

                     

                    The object created by the script moves to the very top of page. Is it possible to move it about three inches lower and then zoom to it so that upper half of the page will become visible instead of first two lines only.

                     

                    Regards,