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 24-01-2007, 08:47
knowbodynow knowbodynow is offline
Senior Member
 
Join Date: Mar 2006
Location: Hatsukaichi near Hiroshima
Posts: 430
Default How Can I reference groups of objects?

I need to know how to refer to groups of objects. For example, if I have selected two groups of objects and I wanted to resize the first group to match the size of the second group how would I reference the objects? Does this make sense?

Thanks,

Chris (Hunt)
Reply With Quote
  #2  
Old 24-01-2007, 12:19
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4
Default

You need to use ShapeRange objects. Look it up on this forum and you'll find plenty of different examples.
Reply With Quote
  #3  
Old 24-01-2007, 17:07
knowbodynow knowbodynow is offline
Senior Member
 
Join Date: Mar 2006
Location: Hatsukaichi near Hiroshima
Posts: 430
Default

Thanks Alex, I did a search as you suggested but I still don't see how to use shaperange in the way I am thinking. Imagine I have a piece of clip art (a group of objects) and a square. I select the clipart and then one square. I want to centre the clipart to the square and resize it to 85% of the squares size. I can't figure out how Coreldraw is referencing the objects. Here is some code I amended from recording a macro.

Code:
Sub sizetoobject()

    Dim px As Double, py As Double
    Dim sx As Double, sy As Double

ActiveDocument.ReferencePoint = cdrCenter
ActiveDocument.Unit = cdrMillimeter

If ActiveDocument Is Nothing Then End
If ActiveShape Is Nothing Then End
        
ActiveLayer.Shapes(1).AlignToShape cdrAlignHCenter, ActiveLayer.Shapes(2), cdrTextAlignBoundingBox
ActiveLayer.Shapes(1).AlignToShape cdrAlignVCenter, ActiveLayer.Shapes(2), cdrTextAlignBoundingBox

px = ActiveLayer.Shapes(2).SizeWidth * 0.85
py = ActiveLayer.Shapes(2).SizeHeight * 0.85

sx = ActiveLayer.Shapes(1).SizeWidth
sy = ActiveLayer.Shapes(1).SizeHeight

ActiveLayer.Shapes(1).Stretch (px / sx), (py / sy)

End Sub
This appears to work, but only once. when I select another piece of clipart and another square it doesn't work. I thought shapes(1) would be the first selected item and shapes(2) the second selected item each time I ran the macro but this doesn't seem to be the case.

How can I name an item if I don't know how Coreldraw is referencing them? I'm obviously missing something and not understanding how it works.

Chris
Reply With Quote
  #4  
Old 25-01-2007, 08:59
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4
Default

Chris,

If you use Layer.Shapes, then the indexing will be the Z-order of shapes on that layer. The topmost shape will be #1, the one directly below it is #2 and so on. That is basically the order as shapes appear in the Object Manager tree.

However if you use ActiveDocument.Selection.Shapes (or ActiveSelection.Shapes) then the selected objects go in the order of selection of the shape. The last selected object will be shape #1, the one before it will be #2 and so on. That is, if you Shift-Click a bunch of objects one after another, the selection list will be built in the reverse order of your selection.

So, to your problem, if you want to select many objects of a clipart and then select a rectangle, you should select the rectangle the last (e.g. marquee-select all your clipart objects and then shift-click the rectangle). This way you will know that your reference rectangle will be the first object in the Selection shape collection and the rest of the object will follow. Then you can separate them like this:

Code:
Dim sRect As Shape
Dim sRestOfObjects As ShapeRange
Set sRect = ActiveSelection.Shapes(1)
Set sRestOfObjects = ActiveSelection.Shapes.AllExcluding(1)
Then you can align your shaperange to the shape or scale and so on. Here is how you would stretch your clipart object and fit them to the 85% of size of the rectangle:

Code:
Sub FitObjects()
    Dim sRect As Shape
    Dim sRestOfObjects As ShapeRange
    Dim x As Double, y As Double
    Dim w As Double, h As Double
    Dim w1 As Double, h1 As Double
    
    Set sRect = ActiveSelection.Shapes(1)
    Set sRestOfObjects = ActiveSelection.Shapes.AllExcluding(1)
    
    sRect.GetBoundingBox x, y, w, h
    w1 = w * 0.85
    h1 = h * 0.85
    
    x = x + (w - w1) / 2
    y = y + (h - h1) / 2
    
    sRestOfObjects.SetBoundingBox x, y, w1, h1, True, cdrCenter
End Sub
I hope this helps.
Reply With Quote
  #5  
Old 25-01-2007, 17:18
knowbodynow knowbodynow is offline
Senior Member
 
Join Date: Mar 2006
Location: Hatsukaichi near Hiroshima
Posts: 430
Default

Thanks Alex,

That was the exact help I needed. Your explanation was very clear. I'd realised I needed to use ActiveSelection.Shapes but I couldn't get that the last object selected would be shape #1, this seems backwards to me but is straightforward once realised. I've got what I wanted working now but would have got nowhere further without your help.

Best wishes,

Chris
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
Trimming multiple objects in one swoop? jahmer General 1 17-11-2006 08:10
Stepping through objects, identifying attributes, storing data for later use Mitsu1 CorelDRAW/Corel DESIGNER VBA 6 08-11-2006 11:09
Glitches with Names of Objects Granite Golem CorelDRAW/Corel DESIGNER VBA 14 01-06-2005 03:38
I need to update objects visibility faster NEHovis Corel Photo-Paint VBA 0 18-07-2003 07:54
How do I reference ArtisticText objects? "Shape Index o andyb CorelDRAW/Corel DESIGNER VBA 1 10-07-2003 14:59


All times are GMT -5. The time now is 00:28.


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