11 Replies Latest reply on Aug 30, 2014 10:48 AM by Obi-wan Kenobi

    Adjust two spreads to the window…

    Obi-wan Kenobi Level 5

      Hi all,


      ID allows us to adjust the spread to the window! This is cool!

      But what I would need is the possibility to adjust 2 contiguous spreads to the window! 

      Any idea! Thanks in advance! 

        • 1. Re: Adjust two spreads to the window…
          Trevorׅ Adobe Community Professional

          Just fetch the layout windows bounds then fetch the spreads (pasteboards) bounds do a bit of maths and change the zoom value

          or if the spread sizes are the same fit the one spread to the window and then reduce the zoom by X%


          Note you can't control directly by script how up down left or right the spreads will appear, sometimes you can temporarily add a point and select it so the focus goes to it and then delete the point.

          • 2. Re: Adjust two spreads to the window…
            Obi-wan Kenobi Level 5

            Hi Trevor,


            The zoom% depends on the spread and the pasteboard. I can find the quite good percent [In the case I'm working on, it is 38%] by approximation. What I want too is the 4 pages centered in the window!

            Finally, what I would need would be a [JS] associated to a keyboard shortcut to do this!

            • 3. Re: Re: Adjust two spreads to the window…
              Laubender Adobe Community Professional & MVP

              Hi, Obi-wan!


              With a little preparation of your document from your side, I can offer you a semi-automatically solution.

              It will work, if you have a "regular" document. Page sizes all equal. Distance from the pages to the "gray area" that is surrounding the pasteboard is equal for every page.


              What we need is something like a helper object, could be a rectangle on a none-printing layer, that is positioned like that:




              Because it should not interfer with other page contents, as a next step it should be made a bit smaller.
              Note: the center of the rectangle is in the spine and in the middle of the gray area that parts one spread from the other.




              Give that helper a unique name in the Layers Panel. I used "zoomHelper" here. Or use a script for that.
              Select the rectangle and run:


              app.selection[0].name = "zoomHelper";


              Position exactly one of these helpers on every spread of your document. Always in the same position.


              To make that easy for you, just do the positioning on spread one and use the following snippet to duplicate the rectangle to every spread with the following code.


              Select the rectangle and run:


              var mySpreads = app.documents[0].spreads.everyItem().getElements();
              for(var n=1;n<mySpreads.length;n++){


              Now, that all preparations are done you can run the following script (before apply a keyboard shortcut for it) when you want to zoom to see two spreads. The script will do the following:


              1. Writes your current selection into a variable for later use

              2. Deselects all

              3. Identifies the helper rectangle by its name, selects the one of the active spread of your active window

              4. Zooms to 38 %

              5. Deselects the helper rectangle

              6. Selects the things stored in the variable in step #1


              var myZoomPercentage = 38;
              var mySelection = app.selection;
              app.activeWindow.zoomPercentage = myZoomPercentage;


              With my laptop and a page size of A4 with two pages in a double sided spread I'm using 35.5 %.






              • 4. Re: Re: Adjust two spreads to the window…
                Laubender Adobe Community Professional & MVP

                To make that "perfect" position the helper rectangle of the last spread at the top of the spread.





                • 5. Re: Re: Adjust two spreads to the window…
                  Trevorׅ Adobe Community Professional

                  Hi Uwe


                  I can't understand why you are creating the helper manually and on mass as apposed to by script and on  temporary bases.


                  I'll give it a go if I get a chance tomorrow.





                  • 6. Re: Adjust two spreads to the window…
                    Laubender Adobe Community Professional & MVP

                    @Trevor – alright, the script could duplicate the helper rectangle from spread one.


                    To expand this a bit:

                    We have two different positions of the helper.
                    1. Spread [0] to [-2] bottom center

                    2. Spread [-1] top center


                    If the user adds pages and spreads during layout phase the script should always check, if the rectangle is there or not. If the activeSpread is the last one in the document (different position of the rectangle).


                    So it would be best, to make that more flexible.
                    The user could create two rectangles, one at the bottom, one at the top of spread two. Then export both individually to IDMS and the script would place one IDMS file depending if the activeSpread is the last one in the document or not. And of course removing it after the script is finished.


                    To get the right percentage for the zoom and calculate the right position of the helper rectangle are difficult.
                    We cannot rely on the bounds of a window. If the window is free floating and not docked to the application frame you get reliable values. If it is docked to the application frame you always get the same values. Even in a situation where two or more windows are viewable at the same time.


                    Then: what is the distance between two spreads? Could we rely on a constant here?
                    Is every pasteboard of every spread the same size? No. Adobe made it flexible. Different influences here.
                    How to get the exact values for the pasteboard?

                    Marc Autret hinted to some facts we could exploid:
                    Indiscripts :: Pasteboard Expander for InDesign CS5-CS6


                    So, you are right. My solution presented in answer #3 is a half-baked one.



                    • 7. Re: Re: Adjust two spreads to the window…
                      Trevorׅ Adobe Community Professional

                      O.k. Came up with a compromise version


                      Read the first line of the script carefully!.

                      Not fully baked to put it mildly but I think over the halfway point.


                      A keyboard shortcut can be set to it using the UI.

                      To make work for 3, 4, 205 spreads use your brain a little bit ;-) (i.e. place the helper on the appropriate spread).






                      // A NOT THE MOST ROBUST SCRIPT
                      // By Trevor to zoom to 2 spreads
                      var gapBetweenPasteBoardsTweak = 10, // Change this according to screen size etc.
                          desiredZoomPercentage = 30, // Change this according to screen size etc.
                          doc = app.properties.activeDocument;
                      !doc && exit();
                      (doc.spreads.length == 1) && exit();
                      gapBetweenPasteBoardsTweak = doc.extractLabel ("gapBetweenPasteBoardsTweak") || app.extractLabel ("gapBetweenPasteBoardsTweak") || gapBetweenPasteBoardsTweak;
                      //  can use app or doc insertLabel("gapBetweenPasteBoardsTweak", 10 or whatever)
                      // Can make a very simple SUI to set these values in a separate script
                      desiredZoomPercentage = doc.extractLabel ("desiredZoomPercentage") || app.extractLabel ("desiredZoomPercentage") || desiredZoomPercentage;
                      // Can use app or doc insertLabel("desiredZoomPercentage", 30 or whatever)
                      var aWindow = app.activeWindow,
                          activeSpread = aWindow.activeSpread,
                          pasteboardVerticalMargin = doc.pasteboardPreferences.pasteboardMargins[1];
                      app.doScript("doubleSpreadZoom (+(doc.spreads[-1] == activeSpread));", ScriptLanguage.JAVASCRIPT, undefined, UndoModes.FAST_ENTIRE_SCRIPT, "Zoom to Double Spread");
                      function doubleSpreadZoom (isLastSpread) {
                          var helperSpread = doc.spreads[activeSpread.index - isLastSpread],
                              y1 = activeSpread.pages[0].bounds[2],
                              y2 = y1 + 2 * pasteboardVerticalMargin + gapBetweenPasteBoardsTweak,
                              x = (helperSpread.pages.length > 1 || doc.spreads[helperSpread.index + 1].pages.length > 1) ? helperSpread.pages[0].bounds[3] : helperSpread.pages[0].bounds[3] / 2,
                              zoomHelper = helperSpread.pages[0].graphicLines.add({geometricBounds: [y1, x, y2, x + 1], strokeColor: "None"}),
                              s = app.selection && app.selection[0];
                          zoomHelper.select ();
                          aWindow.zoomPercentage = desiredZoomPercentage;
                          s && s.select ();
                      • 8. Re: Re: Adjust two spreads to the window…
                        Obi-wan Kenobi Level 5

                        Hi Uwe and Trevor,


                        Thanks for these two very clever scripts.

                        Work all them but I prefer Trevor's approach because it is sufficient unto itself without preparation.

                        However, the 2 scripts have the same two flaws:


                        1 / They do not calculate themselves the zoom percent. Unfortunate, though his calculation is not very complicated: given an entire page (Height H1 // known) appears with an X rate (// known), two pages (H1 = 2 H2 // known) + the gap (G // known = 12.7 mm) between pasteboards will be displayed with a rate Y as calculated: Y = H1 x X ÷ (H2 + G).


                        2 / As, in any case, the rate Y seems to be rounded, we see in the scrolling in one direction or the other, a growing gap in the centering of the two spreads. This problem can be solved as follows by three scripts:

                        Script 0: the script as written.

                        Script 1: It scrolls to the 2 new spreads towards the end of the document ["Go to the next spread"] and then Script 0 is launched again.

                        Script 2: It scrolls to the 2 new spreads towards the beginning of the document ["Go to the previous spread"] and then Script 0 is launched again.


                        Actually, I do the steps 1 and 2 with two little QuicKeys Shortcuts:

                        After I associate an ID keyboard shortcut to your scripts (Uwe/Trevor), I create 2 shortcuts with QK:

                        1/ "Go to the next spread" + launch the script 0

                        2/ "Go to the previous spread" + launch the script 0


                        The result is very cool! 


                        One last point: I have a bug in the script on Trevor, not sure it is due to a bug in his script! 


                        Capture d’écran 2014-08-28 à 16.29.33.png

                        • 9. Re: Re: Adjust two spreads to the window…
                          Trevorׅ Adobe Community Professional

                          Hey that bug doesn't look like mine!

                          I don't have if(theNewLabel== ... in my script!


                          P.s. don't forget to mark the question as answered

                          • 10. Re: Re: Re: Adjust two spreads to the window…
                            Laubender Adobe Community Professional & MVP

                            @Obi-wan – the assumption that the zoom percentage can be calculated easily is wrong.
                            If we consider pasteboards with sizes above the minimum that can be set in the preferences.


                            At least it is not that easy… ;-)

                            The main problem with that is calculating the size of the active window.

                            A window has the bounds property in ExtendScript showing values in pixels. That's ok and would be sufficient to do any calculations based on it. But: The values sometimes are misleading. Every time a window is docked to the application frame you will get the same values, even if there are split views of the same document and the values should be different, because the active window is only part of the whole area the application frame is occupying.


                            I remember discussions about that here in the forum.


                            Now for the other problem with different sized pasteboards inside one document:
                            I found a solution to calculate their size. It's surprisingly easy, if you know how (isn't it always like this?)  ;-)


                            You could use the resolve() method for a spread object to calculate its dimensions according to the pasteboard coordinate system that rules the whole document. Everything in one document (maybe not the objcects on master spreads – I have still to investigate this), be it single pages, single objects on pages, single objects on pasteboards can be described in a coordinate system that spans the whole document (the "gray" small gaps between the individual pasteboards of the spreads included). The origin of that coordinate system is always in something like the middle of spread one (maybe I'm wrong with "always" and "middle" here).


                            And every pageItem could be resolved for its position relative to the "pasteboard coordinate space" that is the area that incloses: all spreads, all pasteboards, all gaps for a single document!


                            So, how will that work?


                            As an example take spread one of a document.


                            The area this individual pasteboard is occupying can be described by:


                            var pasteboardBounds = [];
                            var mySpread = app.documents[0].spreads[0];
                            var xyTopLeftCornerArray = mySpread.resolve
                            var xyBottomRightCornerArray = mySpread.resolve
                            //In coordinate space of the pasteboard (default = points):
                            pasteboardBounds[0] = xyTopLeftCornerArray[0][1];
                            pasteboardBounds[1] = xyTopLeftCornerArray[0][0];
                            pasteboardBounds[2] = xyBottomRightCornerArray[0][1];
                            pasteboardBounds[3] = xyBottomRightCornerArray[0][0];


                            From that on we can describe the area that "pasteboard of spread 1" plus the gap plus "pasteboard of spread 2* " will inclose and set that in relationship to the bounds of our active window to calculate the zoom percentage. (But only if the values of the bounds of the active window are not misleading). Also to note here: the relationshio between screen pixels, zoom percentage and the meassurement unit system an individual document is using. See pixels equals points in InDesign (or not) discussions around for versions after CS5.5.




                            * EDIT: Of course I meant spread 2 here. Or any other spread down the number of spreads. So we can calculate the dimensions of every couple of spreads. Even any geometrical relationship between objects on different spreads! E.g. The distance from two page edges on different spreads…

                            • 11. Re: Re: Re: Adjust two spreads to the window…
                              Obi-wan Kenobi Level 5

                              Hi Uwe,


                              Thank you for continuing to reflect on this Zoom %. I appreciate a lot!! 


                              I realized that an approximation is sufficient. So I proceed as follows:

                              I make appear 2/3 spreads in the ID document window and I do a scan (with pressing Cdm-space // MAC) on 4 pages. This gives me the "famous" Zoom %.

                              In the end, what I would need is that the script takes into account THIS Zoom % without I need to manually edit the script to insert it AND retains it in memory until I define a new one!!