5 Replies Latest reply on Feb 17, 2015 1:11 AM by Loic.Aigon

    Setting exact spaces between two text frames

    johnp45247251 Level 1

      Hi guys,

      I am new to applescript. I need to Setting exact spaces between two text frames.

      It is possible in applescript?

       

      In my indesign page having 2 text frames only. and i have to set exact spaces to 20 mm.

      anyone help me!

        • 1. Re: Setting exact spaces between two text frames
          Loic.Aigon Adobe Community Professional

          Hi,

          If your need is all about spacing text frames, here is a javascript code that should do what you need :

           

          function main(gap) {
            var sel, pi1, pi2, pi1vb, pi2vb, piRight, piLeft, piLeftVb, piRightVb;
            var doc, HU;
            if ( !app.documents.length || (!app.selection instanceof Array) || app.selection.length!=2 ) return;
          
            doc = app.activeDocument;
            HU = doc.viewPreferences.horizontalMeasurementUnits;
            doc.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.MILLIMETERS;
            pi1 = app.selection[0];
            pi2 = app.selection[1];
            pi1vb = pi1.visibleBounds;
            pi2vb = pi2.visibleBounds;
            piRight = ( pi2vb[1] > pi1vb[1] ) ? pi2 : pi1;
            piLeft = piRight==pi2? pi1 : pi2;
            piLeftVb = piLeft.visibleBounds;
            piRightVb = piRight.visibleBounds;
            piRight.visibleBounds = [piRightVb[0], piLeftVb[3]+gap, piRightVb[2], piLeftVb[3]+gap+piRightVb[3]-piRightVb[1]];
            doc.viewPreferences.horizontalMeasurementUnits = HU;
          }
          
          
          main(20);
          

           

          In Applescript, I guess the syntax would be something like set the visible bounds of pi1 to …

           

          On a plus note, you can call this js from Applescript if you want.

           

          Loic

          http://www.ozalto.com

          • 2. Re: Setting exact spaces between two text frames
            johnp45247251 Level 1

            Thank you very much Loic.Aigon

            but i need applescript code, if you known please tell them.

            • 3. Re: Setting exact spaces between two text frames
              Loic.Aigon Adobe Community Professional

              well, if you have to…

               

              
              on main(gap)
                tell application "Adobe InDesign CC 2014"
                if (count of documents) = 0 then return
                set theDoc to active document
                tell theDoc
              
                set HU to get horizontal measurement units of view preferences of theDoc
                set horizontal measurement units of view preferences of theDoc to millimeters
                if (count of items in selection) ≠ 2 then
                return
                else
                set pi1 to item 1 of selection
                set pi2 to item 2 of selection
                set pi1Vb to visible bounds of pi1
                set pi2Vb to visible bounds of pi2
              
                if item 2 of pi2Vb > item 2 of pi1Vb then
                set piRight to pi2
                set piLeft to pi1
                else
                set piRight to pi1
                set piLeft to pi2
                end if
              
                set piRightVb to visible bounds of piRight
                set piLeftVb to visible bounds of piLeft
              
                set visible bounds of piRight to {item 1 of piRightVb, (item 4 of piLeftVb) + gap, item 3 of piRightVb, (item 4 of piLeftVb) + gap + (item 4 of piRightVb) - (item 2 of piRightVb)}
                end if
                end tell
                set horizontal measurement units of view preferences of theDoc to HU
                end tell
              end main
              
              main(20)
              

               

               

              HTH

               

              Loic

              http://www.ozalto.com

              • 4. Re: Setting exact spaces between two text frames
                johnp45247251 Level 1

                Thank you @Loic.Aigon

                you code was really working.


                Once again thank you very much genious.

                • 5. Re: Setting exact spaces between two text frames
                  Loic.Aigon Adobe Community Professional

                  If this was helpful, you can mark your question as answered.