Hi. Does anybody know how to select the largest shape in page?
The problem is the following: I have many shapes within a large rectangle and also some shapes outside the same rectangle.
I want the macro to identify the largest shape in page (the rectangle in this case) and, based on its coordinates, to select all the shapes within the rectangle and group them alltogheter.
Thank you very much!
You can get the largest shape inside For Each-Next loop by checking the Shape.DisplayCurve.Area value. Shapes inside rectangle you can get using ActivePage.SelectShapesFromRectangle
Thank you Shark_ !
Instead of looping through each shape, you could use a little CQL to sort the shapes by the area. Then select the first shape which will be the largest. Here is an example:
Sub SelectByLargestArea() Dim sr As ShapeRange Dim sLargest As Shape Set sr = ActivePage.Shapes.All sr.Sort "@shape1.com.DisplayCurve.Area > @shape2.com.DisplayCurve.Area" Set sLargest = sr.FirstShape sLargest.CreateSelection End Sub
Happy Coding,
-Shelby
Thank you.
Thank you Shelby!
I did it almost the same but I've forgoted about the LastShape solution and I used a loop to find the first shape:
For Each s In sr If sr.IndexOf(s) = 1 Then GoTo .... Next s
Is there another way to select a shape by its index avoiding the loop?
After some testing I've discovered that a faster solution is to search for linear dimensions instead of area.
Using:
sr.Sort "@shape1.width > @shape2.width and @shape1.height > @shape2.height"
instead of:
sr.Sort "@shape1.com.DisplayCurve.Area > @shape2.com.DisplayCurve.Area"
gives a faster response.
Thank you again Shelby!