![]() |
|
#1
|
|||
|
|||
|
hi.
i am trying to create macro to automate creating a rectange 4 mm around an object (probably adding rectangle by holding down shift, double clicking on rectangle tool, then using Expand/Reduce to expand by 4 mm). I cannot get macro to work... Can anybody help? Does anyone have code? Regards, Kyle |
|
#2
|
||||
|
||||
|
This should do what you want I think:
Code:
Sub CreateBoundingRect()
Const ExpandBy As Double = 4
Dim s As Shape
Dim x As Double, y As Double, w As Double, h As Double
ActiveDocument.ReferencePoint = cdrBottomLeft
ActiveDocument.Unit = cdrMillimeter
Set s = ActiveSelection
s.GetBoundingBox x, y, w, h
ActiveLayer.CreateRectangle2 x - ExpandBy, y - ExpandBy, s.SizeWidth + (ExpandBy * 2), s.SizeHeight + (ExpandBy * 2)
End Sub
-Shelby |
|
#3
|
|||
|
|||
|
That is exactly what i was looking for!! Ta very much!.
Hey how can i donate money to you? i find this forum excellent and has improved my efficiency loads as well as my end product for my customers ![]() Ta. Kyle |
|
#5
|
||||
|
||||
|
This one is just for fun
![]() In Designer X4 and a future version of CorelDRAW you'll be able to do this as follows: Code:
Sub CreateBoundingRect2()
Const ExpandBy As Double = 4
Dim rc As Rect
ActiveDocument.Unit = cdrMillimeter
Set rc = ActiveSelection.BoundingBox
rc.Inflate ExpandBy, ExpandBy, ExpandBy, ExpandBy
ActiveLayer.CreateRectangleRect rc
End Sub
|
|
#6
|
|||
|
|||
|
Hey guys, those codes work great so Big thanks to you guys.
I was just wondering if after the rectangle is created would it be possible to group the orginal object with the rectangle? Kyle |
|
#7
|
||||
|
||||
|
Yes, you can. For example, using Shelby's code:
Code:
Sub CreateBoundingRect()
Const ExpandBy As Double = 4
Dim sr As ShapeRange
Dim s As Shape
Dim x As Double, y As Double, w As Double, h As Double
ActiveDocument.Unit = cdrMillimeter
Set sr = ActiveSelectionRange
sr.GetBoundingBox x, y, w, h
sr.Add ActiveLayer.CreateRectangle2(x - ExpandBy, y - ExpandBy, s.SizeWidth + (ExpandBy * 2), s.SizeHeight + (ExpandBy * 2))
sr.Group
End Sub
|
|
#8
|
|||
|
|||
|
Hi Alex. Many thanks for your time..
Unfortunately the macro which should group both the orginal object and the rectangle together does not work. The problem was with the following line near the bottom: sr.Add ActiveLayer.CreateRectangle2(x - ExpandBy............................... Ta. Kyle |
|
#9
|
||||
|
||||
|
I get to correct code from Alex :-) You just need to change the s to sr in that line like so:
Code:
Sub CreateBoundingRect()
Const ExpandBy As Double = 4
Dim sr As ShapeRange
Dim x As Double, y As Double, w As Double, h As Double
ActiveDocument.Unit = cdrMillimeter
Set sr = ActiveSelectionRange
sr.GetBoundingBox x, y, w, h
sr.Add ActiveLayer.CreateRectangle2(x - ExpandBy, y - ExpandBy, sr.SizeWidth + (ExpandBy * 2), sr.SizeHeight + (ExpandBy * 2))
sr.Group
End Sub
-Shelby |
|
#10
|
|||
|
|||
|
You guys are so cool
![]() Thanks a lot - works great. Kyle |
![]() |
| 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 |
| Selecting shapes in rectangle area | lukswa | CorelDRAW/Corel DESIGNER VBA | 2 | 07-10-2008 02:13 |
| Create Rectangle-Shape with positioning | WernerHo | CorelDRAW/Corel DESIGNER VBA | 2 | 06-02-2008 03:40 |
| draw nodes at crossing point between a line and a rectangle | joyJOYJOY | Corel Photo-Paint VBA | 1 | 01-08-2007 13:18 |
| Checking If Artistic Text is on a rectangle shape | knowbodynow | CorelDRAW/Corel DESIGNER VBA | 2 | 16-04-2007 17:47 |
| Tiler-Script, bounding rectangle + CorelDraw 11 | Layout-herber | CorelDRAW CS | 3 | 24-01-2003 01:40 |