![]() |
|
#1
|
|||
|
|||
|
I have the following code that should look for objects on rectangles and group them to the rectangle if found:
Code:
sub groupobjects()
Dim sel As Shape
Dim Gr As Shape
Dim rx As Double, ry As Double, rw As Double, rh As Double
Dim gx As Double, gy As Double, gw As Double, gh As Double
For Each sel In ActivePage.Shapes
If sel.Type = cdrRectangleShape Then
sel.CreateSelection
sel.GetBoundingBox rx, ry, rw, rh
For Each Gr In ActivePage.Shapes
If Gr.Type <> cdrRectangleShape Then
Gr.GetBoundingBox gx, gy, gw, gh
If (gx >= rx) And gx + gw <= rx + rw And _
(gy >= ry) And gh + gh <= rh + rh Then
Gr.AddToSelection
End If
End If
Next Gr
End If
ActiveSelection.Group
Next sel
End sub()
I suspect there is something flawed with my approach but can someone please offer some corrections to the code or suggestions for a more robust approach. Thanks, Chris (Hunt) |
|
#2
|
||||
|
||||
|
Code:
Sub groupobjects()
Dim rect As Shape, sh As Shape
Dim SR As ShapeRange
Dim x#, y#, w#, h#
Set SR = New ShapeRange
ActiveDocument.BeginCommandGroup "Rectanglify"
EventsEnabled = False: Optimization = True: ActiveDocument.PreserveSelection = False
ActiveDocument.ReferencePoint = cdrBottomLeft
For Each rect In ActivePage.FindShapes(, cdrRectangleShape, recursive:=False)
rect.GetBoundingBox x, y, w, h
With ActivePage.SelectShapesFromRectangle(x, y, x + w, y + h, True)
If .Shapes.Count > 1 Then
SR.AddRange .Shapes.All
For Each sh In SR
If Not sh Is rect Then
sh.AlignToShape cdrAlignHCenter Or cdrAlignVCenter, rect
End If
Next
SR.Group
SR.RemoveAll
End If
End With
Next rect
ActiveDocument.PreserveSelection = True: Optimization = False: EventsEnabled = True
ActiveDocument.EndCommandGroup
ActiveWindow.Refresh
Refresh
End Sub
Last edited by wOxxOm; 27-09-2007 at 19:26. |
|
#3
|
|||
|
|||
|
Thanks Os,
I tried using SelectShapesFromRectangle before using the code I posted. Unfortunately I got an error message and I'm also getting one with the code you posted. The line: With ActivePage.SelectShapesFromRectangle(rect.LeftX, rect.TopY, rect.RightX, rect.BottomY, True) Gives a 438 error: object doesn't support this property or method. Is this because I'm using CorelDraw 12? Chris |
|
#4
|
||||
|
||||
|
no. it's because of .LeftX etc properties.
I've changed the code, see message above. |
|
#5
|
|||
|
|||
|
Thanks, Os, it works perfectly now. This will save quite a bit of time aligning objects in grids.
Best wishes, Chris |
|
#6
|
||||
|
||||
|
I'll use it too from now on :-)
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Simple Bar code generator | Webster | Code Critique | 2 | 06-09-2010 01:41 |
| Problem with VBA in Draw X3 | LGD | CorelDRAW/Corel DESIGNER VBA | 8 | 19-01-2006 09:14 |
| Text ENCODE | Craig Tucker | CorelDRAW/Corel DESIGNER VBA | 10 | 26-01-2005 13:59 |
| Paste and Undo List problem | Michael Cervantes | Corel Photo-Paint VBA | 5 | 11-09-2004 04:47 |
| Problem with Export (or Save as) in AI-Format | LOT | CorelDRAW/Corel DESIGNER VBA | 3 | 10-02-2004 14:28 |