Skip to main content
Known Participant
February 18, 2019
Question

geometricsBounds of all selections

  • February 18, 2019
  • 2 replies
  • 303 views

I just wonder if there is a  possibility get geometricBounds of all selection without using "app.executeMenuCommand("group")" ?

For example i have two separate rectangle and i want get geometricsBounds as if they were a group.

Now i use this method:

app.executeMenuCommand("group");

var groupBound  = doc.selection[0].geometricBounds;

app.executeMenuCommand("ungroup");

Can it be done better than through executeMenuCommand?

This topic has been closed for replies.

2 replies

CarlosCanto
Community Expert
Community Expert
February 18, 2019

grouping and ungrouping works fine except when items live in different layers. It will also cause problems if items overlap other unselected items.

besides looping through your selected items as suggested above, you could create a temporary artboard, fit it to selection, get artboard bounds, remove temp artboard.

Disposition_Dev
Legend
February 18, 2019

unfortunately, doc.selection is an array of objects and thus doesn't have the same properties as a normal object.

The first thing that comes to mind is that you could loop the selection array to locate the objects that fit the following criteria: farthest left, highest, farthest right (then you have to add the width of the item), lowest (then you have to subtract the height of the item).

You'll also have to be careful of clipping masks, because the geometric bounds will include anything that's clipped inside of that mask so you may get unexpected results.

I'm not sure this will be easier than grouping and ungrouping though.. and it's certainly far less efficient.

Hope this helped..