Skip to main content
Inspiring
March 7, 2016
Question

Get geometric bounds for selection

  • March 7, 2016
  • 1 reply
  • 2458 views

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.

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

  

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.

This topic has been closed for replies.

1 reply

Alexander Ladygin
Inspiring
March 11, 2016

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[bounds][0] );

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

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

        h.push( arr[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' );