Hello all, it's been quite a while.
At my workplace we have been using CorelDRAW 2018 with several complex custom-built VBA macros made by me. This involves nesting, object manipulation, large scale duplication and several other things that tend to take quite while.
I remember seeing somewhere on the website that the performance in 2020 has been drastically improved and decided to put it to a test. Just making a simple macro where 10000 objects are created and then rotated.
Pure creation was about 5 times faster and creation, then rotation about 2 times faster. Of course, I used this excellent optimization advice from GDG_John.
Now my question is - does the 2020 version have any other optimization tools for VBA macros?
Alright, so... Based on this early testing I started implementing a more complex macro into 2020 and at the beginning everything seemed nice and efficient. I kept adding more operations, mostly lots of shape movement... I test the macro and it takes about 30 seconds for some fairly complex movement activities. Well, sounds decent, let's test it in 2018 just for fun... 3 seconds!?
So it turns out 2020 is faster at almost anything (that is why I have object creation and Contours - at first it was twice as fast as 2018), but gets slower and slower the more object movement is done.
I could not use VirtualShapes, because they do not support Contours, which I need. Anyone care to try this demo code I made (the real one has more movement and the difference exponentially grows)? Thanks!
Private Sub SpeedTest() Optimize True Dim S As Shape, A As Shape Dim X As Byte, Y As Byte, P As Byte Dim T As Single Dim E As Effect T = Timer Dim Doc As Document Set Doc = CreateDocument For X = 1 To 20 For Y = 1 To 20 Set S = ActiveLayer.CreatePolygon2(X, Y, 1, Y Mod 5 + 3) Set E = S.CreateContour(cdrContourOutside, 0.5) Set A = E.Separate.Shapes.First A.ConvertToCurves For P = 1 To 10 A.Move 1, 1 Next P Next Y Next X Optimize False MsgBox Timer - T End Sub Sub Optimize(Use As Boolean) If Use Then EventsEnabled = False Optimization = True ActiveDocument.SaveSettings Else ActiveDocument.RestoreSettings EventsEnabled = True Optimization = False ActiveWindow.Refresh End If End Sub
You can try to do similar operations as to create objects (using virtual shapes), contours, moving in different cycles
Private Sub SpeedTest2()
Optimize True
Dim S As Shape, A As Shape
Dim X As Byte, Y As Byte, P As Byte
Dim sr_poly As New ShapeRange Dim sr_move As New ShapeRange
Dim T As Single
Dim E As Effect
T = Timer
Dim Doc As Document Set Doc = CreateDocument Doc.Activate
For X = 1 To 20 For Y = 1 To 20
'create objects using virtual shapes Set S = Doc.TreeManager.VirtualLayer.CreatePolygon2(X, Y, 1, Y Mod 5 + 3) sr_poly.Add S Next Y Next X Set sr_poly = Doc.LogCreateShapeRange(sr_poly)
'create effects
For Each S In sr_poly Set E = S.CreateContour(cdrContourOutside, 0.5) Set A = E.Separate.Shapes.First A.ConvertToCurves sr_move.Add A Next S
For P = 1 To 10 sr_move.Move 1, 1 'all the objects are moved similarry, so we move them all at once Next P
Optimize False
MsgBox Timer - TEnd Sub
Thanks, I will try to implement some of this for sure, but in general my example was just something very simple and not quite what I'm doing with the real macro.
There I am working with existing shapes, giving them contours, separating them, moving things around, etc.
But still - do you have 2020 and an older version in hand to give the difference a try? Simple shape movement being much slower in 2020 seems really weird. Certainly surprised me after the promise of solid performance improvements.
I tryed the code in X7 and in 2020. 2020 is slower. I'm too lazy to check which operation is slower than in X7, so I trust you that it is the "move".
Thanks, would be neat to hear from someone from Corel what is up with that...
Joe said:Thanks, would be neat to hear from someone from Corel what is up with that...
I think it would be great if those interested in automation had some - even a little bit of - access to Corel developers.
I'm aware of a number of things that are outright broken, and simply don't work correctly when using the API. With essentially no access to the Corel developers, I have zero hope that those problems will ever be corrected.