OberonPlace.com Forums  

Go Back   OberonPlace.com Forums > Developer Forums > VBA > CorelDRAW/Corel DESIGNER VBA

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 27-09-2007, 08:44
knowbodynow knowbodynow is offline
Senior Member
 
Join Date: Mar 2006
Location: Hatsukaichi near Hiroshima
Posts: 367
Default Problem withgrouping code

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()
This seems to work but I can't find a way to centre the object on the rectangle before grouping. As an experiment I tried substituting activeselection. group with activeselection.delete but this gave me an error.

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)
Reply With Quote
  #2  
Old 27-09-2007, 12:16
wOxxOm's Avatar
wOxxOm wOxxOm is offline
Senior Member
 
Join Date: Mar 2005
Posts: 836
Default

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.
Reply With Quote
  #3  
Old 27-09-2007, 19:06
knowbodynow knowbodynow is offline
Senior Member
 
Join Date: Mar 2006
Location: Hatsukaichi near Hiroshima
Posts: 367
Default

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
Reply With Quote
  #4  
Old 27-09-2007, 19:26
wOxxOm's Avatar
wOxxOm wOxxOm is offline
Senior Member
 
Join Date: Mar 2005
Posts: 836
Default

no. it's because of .LeftX etc properties.
I've changed the code, see message above.
Reply With Quote
  #5  
Old 27-09-2007, 20:52
knowbodynow knowbodynow is offline
Senior Member
 
Join Date: Mar 2006
Location: Hatsukaichi near Hiroshima
Posts: 367
Default Great Stuff!

Thanks, Os, it works perfectly now. This will save quite a bit of time aligning objects in grids.

Best wishes,

Chris
Reply With Quote
  #6  
Old 27-09-2007, 20:54
wOxxOm's Avatar
wOxxOm wOxxOm is offline
Senior Member
 
Join Date: Mar 2005
Posts: 836
Default

I'll use it too from now on :-)
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

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


All times are GMT -5. The time now is 18:24.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Copyright © 2011, Oberonplace.com