7 Replies Latest reply on Nov 11, 2013 11:56 AM by greenrookie

    Custom zoom script

    Braxton65 Level 1

      I found a script by Jongware at InDesign Secrets for fitting on a page and then zooming:

       

      app.layoutWindows[0].zoom(ZoomOptions.FIT_PAGE);

      try {app.layoutWindows[0].zoomPercentage = Number(app.activeScript.name.match(/\d+/)[0]);} catch (e) {};

       

      I modified it to fit on the spread and then zoom:

       

      app.layoutWindows[0].zoom(ZoomOptions.FIT_SPREAD);

      try {app.layoutWindows[0].zoomPercentage = Number(app.activeScript.name.match(/\d+/)[0]);} catch (e) {};

       

      It works great for my needs if no items are selected on the spread.  However, the problem is that when a frame(s) is selected it doesn't center the spread anymore.  The center point (vertically and horizontally) becomes the center of the frame or group of frames selected.  Would anyone know how to modify this script so that it it is frame selection independant?  Thanks.

        • 1. Re: Custom zoom script
          John Hawkinson Level 5

          Isn't this a problem with the original script? InDesign centers the zooming around the current selection.

          You can save the selection, clear it, and then restore it afterwards. Add at the beginning (untested):

           

          var oldsel = app.selection;
          app.select(null);
          

          and at the end:

          app.select(oldsel);
          
          • 2. Re: Custom zoom script
            Braxton65 Level 1

            Thank you John.  Works great.

             

            I'll add for anyone refering to this in the future that the name of the script sets the zoom level, ie...    zoom110.jsx will zoom to 100%

            • 3. Re: Custom zoom script
              Tom Usrey Level 3

              Don't you mean zoom110.jsx will zoom to 110% ?? (not 100%?)

              • 4. Re: Custom zoom script
                Braxton65 Level 1

                Thanks Tom.  That's correct.

                • 5. Re: Custom zoom script
                  greenrookie Level 2

                  Hello everyone,

                   

                  Can anyone help extend the script so I can do this:

                   

                  For example, I have 2 document windows open (one has a spread and one is a single page). I then I select 'arrange documents.' This will tile the windows and I can use this code to center and fit the document to the window.

                   

                  for (i=0; i < app.layoutWindows.length; i++){

                  app.layoutWindows[i].zoom(ZoomOptions.FIT_PAGE) + app.layoutWindows[i].zoom(ZoomOptions.FIT_SPREAD);

                  }

                   

                  I would like the window with a single page to match the zoom of the spread so they are all at the same zoom level.

                   

                  Many thanks in advance.

                   

                  gr

                  • 6. Re: Custom zoom script
                    [Jongware] Most Valuable Participant

                    This operation doesn't make any sense:

                     

                    app.layoutWindows[i].zoom(ZoomOptions.FIT_PAGE) + app.layoutWindows[i].zoom(ZoomOptions.FIT_SPREAD);

                     

                    .. how can you 'add' two commands together? I think what happens is that the first command is executed (fit page), then the next command (fit spread), and then the returned values are added up. This function does not return a value, so it basically adds "undefined" to "undefined" -- but that's okay, you never ask what the sum is anyway. And you end up with 'Fit spread'.

                     

                    According to my CS4, the zoom percentage is the same for PAGE as for SPREAD. Makes sense too: the window height is the same, and since both the single page and the spread are taller than the window height, they both fit vertically. If you find it's different for you, then you'll (probably) need to compare the zoom percentage of PAGE and SPREAD and then use the smallest.

                    • 7. Re: Custom zoom script
                      greenrookie Level 2

                      Thanks Jongware,

                       

                      I'm at the kludging level of JS and thought "+" was a "&" from Applescript ^_^