1 Reply Latest reply on Mar 10, 2016 9:38 PM by Alexander Ladygin

    Get geometric bounds for selection

    johnp45247251 Level 1

      Hi everyone!

       

      When i am paste an image into illustrator document, To get the geometric bounds of selection using applescript.

      But, not exactly to get values.

      Screen Shot 2016-03-07 at 5.12.48 PM.png

       

      Because, the above image having hiding text frames in document.

      Screen Shot 2016-03-07 at 5.13.09 PM.png

        

      This is my code,

       

        tell application "Adobe Illustrator"

                tell document 1

                      set vb to visible bounds of item 1 of selection   ------  here wrongly to get value

                      set artboard rectangle of first artboard to vb

                end tell

           end tell

       

       

      Please any idea to fix this.

       

      Thanks,

      John Peter.

        • 1. Re: Get geometric bounds for selection
          Alexander Ladygin Level 2

          Option in javascript:

          function getBounds ( arr, bounds ) {

              var x = [], y = [], w = [], h = [],

                  bounds = bounds || 'geometricBounds';

              for ( var i = 0; i < arr.length; i++ ) {

                  x.push( arr[i][bounds][0] );

                  y.push( arr[i][bounds][1] );

                  w.push( arr[i][bounds][2] );

                  h.push( arr[i][bounds][3] );

              }

              x = Math.min.apply( null, x );

              y = Math.max.apply( null, y );

              w = Math.max.apply( null, w );

              h = Math.min.apply( null, h );

              return rect = [ x, y, w, h ];

          };

          activeDocument.artboards[0].artboardRect = getBounds( selection, 'visibleBounds' );