How can I modify this code where I only want each shape with a bounding box drawing around them?
Here is an example Shelby made (modified?) below showing a feature where each line of text has a bounding box.
Sub TextRectangles() Dim s As Shape Dim srSelection As ShapeRange Dim srStateBefore As ShapeRange Dim srStateAfter As ShapeRange Dim srDuplicateText As ShapeRange Dim x As Double, y As Double, w As Double, h As Double Set srSelection = ActiveSelectionRange 'Get the current selection ' Get all the text objects before the operation Set srStateBefore = ActivePage.FindShapes(Type:=cdrTextShape) 'Duplicate each text shape that is more than one line For Each s In srSelection If s.Type = cdrTextShape Then If s.Text.Story.Lines.Count > 1 Then s.Duplicate.BreakApart End If Next s ' And now after the operation Set srStateAfter = ActivePage.FindShapes(Type:=cdrTextShape) ' Any new objects are the ones created by the BreakApart calls ' Remove all the "old" objects srStateAfter.RemoveRange srStateBefore Set srDuplicateText = srStateAfter.ReverseRange srDuplicateText.ConvertToCurves 'So we can create tight fitting rectangles For Each s In srDuplicateText s.GetBoundingBox x, y, w, h ActiveLayer.CreateRectangle2 x, y, w, h Next s srDuplicateText.Delete 'Delete our duplicates srSelection.CreateSelection 'Set the selection back to the orginal Set srStateBefore = Nothing Set srStateAfter = Nothing Set srDuplicateText = Nothing End Sub
see my image example.
This is actually much easier then when working with text. For shapes you can do something like this:
Sub BoundingBoxes() Dim s As Shape, srRects As New ShapeRange Dim x As Double, y As Double, w As Double, h As Double For Each s In ActivePage.Shapes.FindShapes() s.GetBoundingBox x, y, w, h srRects.Add ActiveLayer.CreateRectangle2(x, y, w, h) srRects.SetOutlineProperties 0.02778, OutlineStyles(5), CreateCMYKColor(0, 100, 100, 0) Next s End Sub
Not sure if you wanted the bounding boxes red and dashed, but tossed it in just in case.
-Shelby
Shelby Moore said: This is actually much easier then when working with text. For shapes you can do something like this: Sub BoundingBoxes() Dim s As Shape, srRects As New ShapeRange Dim x As Double, y As Double, w As Double, h As Double For Each s In ActivePage.Shapes.FindShapes() s.GetBoundingBox x, y, w, h srRects.Add ActiveLayer.CreateRectangle2(x, y, w, h) srRects.SetOutlineProperties 0.02778, OutlineStyles(5), CreateCMYKColor(0, 100, 100, 0) Next s End Sub Not sure if you wanted the bounding boxes red and dashed, but tossed it in just in case. -Shelby
Beautiful. One thing - ActiveSelection - doh! It bounded every single thing on the page....you are very awesome.