OberonPlace.com Forums  

Go Back   OberonPlace.com Forums > Developer Forums > VBA > Code Critique

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 22-04-2004, 12:25
lasergraver
Guest
 
Posts: n/a
Default Any way to make this faster?

This code creates a small rectangle then rotates duplicates from a common center point to create a circle. It seems somewhat sluggish to me. I tried recording this as a macro but that created 3 pages of code in VBA for CorelDraw 12 and was no faster.

Any ideas on making this run faster?

Code:
Sub Make_Outside_Circle()
    
    Dim s1 As Shape
    Set s1 = ActiveLayer.CreateRectangle(0.443327, 1.308433, 0.609051, 1.212823)
    
    s1.Fill.UniformColor.CMYKAssign 0, 0, 0, 100
    s1.Outline.SetProperties 0#
    s1.ConvertToCurves
    ActiveDocument.ReferencePoint = cdrCenter
    s1.SetSize 0.047, 0.007
    s1.SetPosition 1.023, 0.875
    s1.RotationCenterX = 1.75
    s1.RotationCenterY = 0.875
    
    Dim dup1(119) As ShapeRange
    Set dup1(1) = s1.DuplicateAsRange()
    
    dup1(1).RotateEx 3#, 1.75, 0.875
    
    For L = 2 To 119
        m = L - 1
        Set dup1(L) = dup1(m).Duplicate()
        dup1(L).RotateEx 3#, 1.75, 0.875
    Next L
    
End Sub
Many thanks!
Reply With Quote
  #2  
Old 22-04-2004, 16:53
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4
Default Re: Any way to make this faster?

Here is slightly optimized version of your program:

Code:
Sub Make_Outside_Circle()
    Dim i As Long
    Dim s As Shape
    Dim sr As New ShapeRange
    
    ' Turn on optimizations
    Optimization = True
    EventsEnabled = False
    ActiveDocument.PreserveSelection = False
    
    ' Create first object
    Set s = ActiveLayer.CreateRectangle(0.443327, 1.308433, 0.609051, 1.212823)
    s.Fill.UniformColor.CMYKAssign 0, 0, 0, 100
    s.Outline.SetProperties 0#
    s.ConvertToCurves
    ActiveDocument.ReferencePoint = cdrCenter
    s.SetSize 0.047, 0.007
    s.SetPosition 1.023, 0.875
    sr.Add s

    ' Create duplicates
    For i = 1 To 119
        Set s = s.Duplicate
        s.RotateEx 3, 1.75, 0.875
        sr.Add s
    Next i
    
    ' Turn off optimizations
    Optimization = False
    EventsEnabled = True
    ActiveDocument.PreserveSelection = True
    
    ' Select all the created objects
    sr.CreateSelection

    ' Refresh the screen
    ActiveWindow.Refresh
    Application.Refresh
End Sub
Works about 5 times faster (it took 0.12 seconds to create the objects, comparing to 0.59 with the original macro).

The main performance gainer is the Optimization property which disables some extra updates (screen, toolbars, etc).
Reply With Quote
  #3  
Old 22-04-2004, 20:33
lasergraver
Guest
 
Posts: n/a
Default

Alex,

WOW! I pretty much expected someone with more experience than me to make this at least twice as fast but 5 times faster!!! UNBELIEVABLE!

I obviously need to learn much more about VBA... never even heard of the Optimization property. Is there a good source for this information?

Thanks again... You truly are a wizard.
Reply With Quote
  #4  
Old 23-04-2004, 00:06
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4
Default

Well, Application.Optimization is a property of CorelDRAW application which prevents the application from constantly updating itself and recalculating selections, bounding boxes and other information which will be invalid on the next operation anyway. There is no reason of updating the status bar with the current selection each time you create one of the 200 objects you need to create, right? So, that's the idea behind Optimization property.

I guess the best place to look for this kind of info is here, in the CorelDRAW VBA help file (just hit F1 on any of the methods/properties in VBA editor) or in CorelDRAW VBA Programming guide manual (look in Start>All Programs>CorelDRAW Graphics Suite 12>Documentation).
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
How can I make a macro time out? Rick Randall CorelDRAW/Corel DESIGNER VBA 6 09-02-2005 11:16
An Idea for a handy and easy to make macro vallentin Macros/Add-ons 2 16-03-2004 11:35
Trying to make buttons from my scripts click101 CorelDRAW/Corel DESIGNER VBA 0 10-09-2003 10:41
I need to update objects visibility faster NEHovis Corel Photo-Paint VBA 0 18-07-2003 07:54
How can i make a CorelDraw addin under Visual C++ andrej CorelDRAW/Corel DESIGNER VBA 2 15-04-2003 09:40


All times are GMT -5. The time now is 16:10.


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