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 13-08-2004, 07:59
lasergraver
Guest
 
Posts: n/a
Default Clearing Undo List

Howdy all,

Is there a way to clear the Undo list in CD 12 through VBA?

Many thanks,
BA
Reply With Quote
  #2  
Old 13-08-2004, 11:18
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4
Default Re: Clearing Undo List

Quote:
Originally Posted by lasergraver
Is there a way to clear the Undo list in CD 12 through VBA?
I don't think this is possible, but why do you need this?
Reply With Quote
  #3  
Old 13-08-2004, 16:05
lasergraver
Guest
 
Posts: n/a
Default

Hey Alex,

I'm not sure that I really do need it....

I was using the Undo to walk backwards through a project to make sure there were no unnecessary or wasted operations performed. Kind of checking up on myself. Being able to do this made wonder if there was a way to prevent it. I didn't even see a way in CD12 to clear the Undo list.

Thanks for replying,
BA
Reply With Quote
  #4  
Old 13-08-2004, 17:54
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4
Default

Yes, you can clear the Undo stack manually. Go to Tools>Undo docker and then click the Clear Undo List button at the end of the window.

However if I understand you correctly, you just want to prevent the user from seeing all the individual steps your macro does. This is easily done in VBA. You need to use Document.BeginCommandGroup and Document.EndCommandGroup commands to show all the steps your macro does as a single Undo entry.

This way your macro looks like a single command for the user and can be easily undone and redone, as any other CorelDRAW command. Here is how you do it:

Code:
ActiveDocument.BeginCommandGroup "Your undo command goes here"
' ... do something in the document
ActiveDocument.EndCommandGroup
One word of caution though. Be very careful with these commands. Always make sure that once BeginCommandGroup is executed, the EndCommandGroup must be called too, or else the Undo stack will be corrupt.

The best way to ensure this is to implement runtime error handling. Even if something happens during your macro execution, you still execute EndCommandGroup:

Code:
Sub TestUndo()
    Dim n As Long
    Dim s As Shape
    
    ActiveDocument.BeginCommandGroup "Generate random shapes"
    On Error GoTo ErrHandler
    
    For n = 1 To 100
        Set s = ActiveLayer.CreateRectangle(Rnd() * 8, Rnd() * 11, Rnd() * 8, Rnd() * 11)
        s.Fill.UniformColor.RGBAssign Rnd() * 255, Rnd() * 255, Rnd() * 255
    Next n
    
ExitSub:
    ActiveDocument.EndCommandGroup
    Exit Sub
    
ErrHandler:
    MsgBox "Unexpected error occured: " & Err.Description, vbCritical
    Resume ExitSub
End Sub
The above example creates 100 randomly colored rectangles. When the macro is executed, the Edit menu will have "Undo Create random shapes" item. Selecting it will undo the creation of all the 100 rectangles.

There is a slight chance that the macro above will fail when the random function for both left and right or top and bottom rectangle edges will produce the same values (that is, the rectangle will have either zero length or zero height). This will make the Layer.CreateRectangle method to fail. However because of the above statement On Error Goto ... the execution will be transferred to the handler, an error message box will be presented to the user and the macro resumes execution at EndCommandGroup command and terminates. So, even in the critical situation of run-time error, the macro will not screw up the document.

Of course, it is better to create the macro in a manner whcih will not fail (add extra checks to ensure that the rectangle is not created of zero size), but then the user might run the macro on a document with a locked layer or with no document at all. So, critical situations might happen, and it is better to plan for them

I hope this helps.
Reply With Quote
  #5  
Old 15-08-2004, 11:34
lasergraver
Guest
 
Posts: n/a
Default

Alex,

Thanks for your reply. That is exactly what I was looking for.

The macro I am working on is for creating both male and female dies for notary seals. It doesn't bother me that someone may be able to use Undo to see the steps in creating this but undoing any steps might make the dies not fit properly.

I create macros only for my own amusement and to automate production so other employees can work when I am not in the office without having to really know too much about CorelDraw. Once completed I will be happy to give this to anyone interested.

Your help with this has been invaluable.

Best Regards,
BA
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
Someone make an Active List Font macro dungbtl CorelDRAW/Corel DESIGNER VBA 8 28-10-2019 09:53
List names of files located in a folder RVogel CorelDRAW/Corel DESIGNER VBA 1 31-03-2005 16:14
Undo several steps with one click... dungbtl CorelDRAW/Corel DESIGNER VBA 1 13-12-2004 13:21
Paste and Undo List problem Michael Cervantes Corel Photo-Paint VBA 5 11-09-2004 04:47
sorted font list in VBA? lasergraver CorelDRAW/Corel DESIGNER VBA 2 11-05-2004 05:52


All times are GMT -5. The time now is 13:35.


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