Hi.
I am attempting to create a rectangle of a specified size at a specified location. I have specified millimeters as the units. The rectangle size is 150mm wide by 40mm high. The page x,y location is 325, 240. I can get the script to add the rectangle, but it is placed at the bottom left corner of the page and is really small. The macro appears to be ignoring my specified location and size. I have used both create rectangle and create rectangle 2 commands without success. I run my macros outside of Corel Draw as vbs files. Detailed below is my macro:
Dim Software
Dim ActivePage
Dim Page
Dim Layer
Dim Shape
Set Software = CreateObject(CorelDraw)
With Software.OpenDocument(FileName)
.Activate
.Unit = cdrMillimeter
.ReferencePoint = cdrCenter
Set ActivePage = .Pages.First
ActivePage.Layers("Details").Activate
Set Shape = ActivePage.ActiveLayer.FindShape("Logo")
If Not Shape Is Nothing Then
MsgBox "Logo found"
Shape.CreateSelection
Shape.Delete
ActivePage.ActiveLayer.CreateRectangle 325, 240, 150, 40
Else
MsgBox "Logo Not Found"
End If
End With
I have attempted to use the set position and set size commands but I get an error advising the reference object no longer exists. In attempt to fix this I added to the macro create selection to select the newly created rectangle (even though this is still selected in Corel Draw at the end of the macro). This second create selection does not prevent the reference object error.
Set Shape = ActivePage.ActiveLayer.FindShape("Rectangle")
Shape.SetPosition 325, 240
Shape.SetSize 150, 40
dmarkey said:I can get the script to add the rectangle, but it is placed at the bottom left corner of the page and is really small.
I'm not sure what the code at the beginning is for. I'm guessing that it is to run VBA inside another program and, is probably not the reason for the size problem.
With a document open, extracting the essential lines from your code:
With ActiveDocument .Unit = cdrMillimeter ActivePage.ActiveLayer.CreateRectangle 325, 240, 150, 40 End With
seems to be sufficient to create a correctly sized rectangle in the specified position.
Does your document have a world scale other than 1:1 ? If it does then you probably need to take that into account when you define the size of the rectangle.
Hi. I do have a world scale different to 1:1. For this particular drawing I have a world distance of 8mm to 1mm of page distance (that is, a scale of 1:8). If I increase the values by a multiple of 8 it reduces the size of the rectangle. The length and width goes from 0.14mm wide by 0.16mm high to 0.7mm wide by 0.064mm high. If I increase this scale factor by a multiple of ten (that is, multiply the values by 80) then the rectangle does increase in size but not to the size I need. How do I factor in the scale of the drawing? As I use Corel Draw to design waterway signs the world scale varies depending on the size of the sign to get it to fit onto an A4 page. I have also noticed factoring in the scale into the location values does place the rectangle to a different location. Once I correctly factor the scale for the size this same factor should place the rectangle on to the location I want.
I have noticed I get an error "The referenced object no longer exists" when I go to change something with the newly created rectangle (for example, change its name). I have tried the create selection command but the error still persists. Do I need to select the rectangle once it has been created and if so why is the create selection command not doing this or not resolving the error. I have noticed if I use the same script to find and select a different shape within the drawing the macro runs without error and correctly selects the shape. Why is this not working with the newly created shape? I have the name spelt correctly in the macro including the space after the name that Corel Draw includes in the naming of a new rectangle shape. Below is part of my macro.
ActivePage.ActiveLayer.CreateRectangle 26000, 19200, 12000, 3200, 0, 0 Set Shape = ActivePage.ActiveLayer.FindShape("Rectangle ") Shape.CreateSelection Shape.Name = "Logo"
Regards, Dave.