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 24-04-2004, 11:59
johndankey
Guest
 
Posts: n/a
Default Trying to get my Time Recording script running...

I'm trying to automate a time-recording script so I can keep track of how long it takes me to paint each of my images.

What I planned in Draw 10, is to have a project, TimeRecording, which contains a "ThisDocument" object, which has a GlobalDocument_OpenDocument subroutine. This sub would record the time in a Document.Property. An equivalent subroutine upon the close of the document would record the difference.

Since GlobalDocument_OpenDocument has not been working on all cases (it will work if you use the open dialog, but not if you open from Explorer), I've been starting it up manually.

Now I have Draw 12. I had hoped they fixed this problem, but GlobalMacroStorage_DocumentOpen still works the same way. I resigned myself to continuing to (try to remember to) start the macro manually, when I had the (almost :wink: ) ingenious idea of putting a subroutine in the ThisDocument object of each document (no need to manually insert it, just put it in the template). That works. Some of the time. Sometimes, I get a Run Time error 91 (Object Variable... not set) from time to time with the line that attempts to access the Document.Property property. It's as if the macro is running before the document is loaded!

Any ideas?

johndankey
Reply With Quote
  #2  
Old 24-04-2004, 21:22
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4
Default Re: Trying to get my Time Recording script running...

I'm not sure what the problem might be. If I understand you correctly, you placed the macro in a CDT file whcih you then use to create your documents. Is that correct? And sometimes you receive DocumentOpen event with the Document parameter not initialized properly? Do you have any pattern as to when this happens? Any chance of figuring the condition when this happens.

However as far as I can tell, the bug of DocumentOpen event not firing when a document is open from Explorer or through Drag'n'drop, this should be fixed in the upcoming service pack.

P.S. As a question, have you considered using VAKCER Project Tracker which was designed to do exactly what you try to do - just keep track of open documents and log time you spend working with each of them. In addition, it doesn't time just the time between you open and close a document, but actual time you work with it. If you switch to another application or document, VPT will follow you along. I hope this helps.
Reply With Quote
  #3  
Old 24-04-2004, 22:32
johndankey
Guest
 
Posts: n/a
Default Re: Trying to get my Time Recording script running...

Alex,

Quote:
Originally Posted by Alex
I'm not sure what the problem might be. If I understand you correctly, you placed the macro in a CDT file whcih you then use to create your documents.
Originally in a CDT, yes. Once I save that document, it is, of course, a CDR.

Quote:
And sometimes you receive DocumentOpen event with the Document parameter not initialized properly?
Huh? The ThisDocument.DocumentOpen event occurs when I open the document (as it should), but when it occurs, the Document.Properties haven't been initialized.

I have checked it a little more scientifically. The Document.Properties property is not initialized until after my script is finished. It appears the DocumentOpen event is fired before the document is loaded. (If I have another document open, the script just uses its Properties, rather than the Properties of the one it is opening.

Quote:
However as far as I can tell, the bug of DocumentOpen event not firing when a document is open from Explorer or through Drag'n'drop, this should be fixed in the upcoming service pack.
That would be great.

Quote:
P.S. As a question, have you considered using VAKCER Project Tracker which was designed to do exactly what you try to do - just keep track of open documents and log time you spend working with each of them. In addition, it doesn't time just the time between you open and close a document, but actual time you work with it. If you switch to another application or document, VPT will follow you along. I hope this helps.
I did try using VPT. However, my script also logs which palette is used & restores that palette when the document is reopened. Eventually, I'll get it to save other per document variables (which workspace, snap-to status & probably others). I'm sure yours is better at keeping time, but it drives me crazy to have to find palettes again!

johndankey
Reply With Quote
  #4  
Old 25-04-2004, 09:48
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4
Default Re: Trying to get my Time Recording script running...

I'll dig a bit deeper and see if I can find anything relevant as to why the Properties of the new document don't work when opening a new document...
Reply With Quote
  #5  
Old 25-04-2004, 10:19
johndankey
Guest
 
Posts: n/a
Default

Alex,

Thanks. I think we're going to find that instead of being called DocumentOpen, it should probably be the JustBeforeTheDocumentIsActuallyOpened Event. I'll try, too, to figure a work around of some sort.

johndankey
Reply With Quote
  #6  
Old 25-04-2004, 14:29
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4
Default

I did a few tests and so far it seems to work OK for me. Of course, I didn't put the event handler in a CDT (i'm not even sure if this can be done in the first place, just haven't tried it yet), but I did try it in a global GMS module and it seemed to work OK. I was able to receive the DocumentNew and DocumentOpen events and I was able to use the Doc.Properties method in both of them with success.

Could you post some of your code. Just curious what exactly you are doing which could cause this to fail...
Reply With Quote
  #7  
Old 25-04-2004, 21:24
johndankey
Guest
 
Posts: n/a
Default

Alex,

You're going to have a nice laugh. I turns out I was using the ActiveDocument properties. Since the document wasn't fully loaded, it was not active!

So I used ThisDocument to reference the document instead of ActiveDocument - which works in the ThisDocument... uh... module(?).

So far, so good.

By the way, you can definitely put an event handler in a template!

Thanks for the help.

johndankey
Reply With Quote
  #8  
Old 26-04-2004, 07:01
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4
Default

Ok, that's good to know. However I would still put your event handlers in a separate GMS file. Thus the events will be fired for every document created or opened, even for the ones you created before you put the macro in the template. And it is quite easy to modify it in case you need to change something. Just edit it in one place rather than opening all those documents one by one and adding your changes in each of them manually.
Reply With Quote
  #9  
Old 26-04-2004, 08:05
johndankey
Guest
 
Posts: n/a
Default

Alex,

My understanding of "event handler" must be faulty. In the ThisDocument object is the script:
Code:
Private Sub Document_Open()
    GMSManager.RunMacro "TimeRecording", "mdlPerDocument.OpenDoc", ThisDocument
End Sub
mdlPerDocument.OpenDoc handles the processing. I'm under the impression that Document_Open() is the called the event handler :?:

johndankey
Reply With Quote
  #10  
Old 26-04-2004, 09:00
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4
Default

Yes, that's correct. But at the same time, you can have more than one handler for the event. Each "document" based project (as the one in a document, with ThisDocument node) will handle events from that document only. However there is a chance to install "global" event handlers which will handle events from any document.

To do this, you will need to add the handler to a GMS module. For example, use the GlobalMacros module and go to GlobalMacroStorage node and add event such as DocumentOpen. It has the document in which the event occured as a parameter:

Code:
Private Sub GlobalMacroStorage_DocumentNew(ByVal Doc As Document, ByVal FromTemplate As Boolean, ByVal Template As String, ByVal IncludeGraphics As Boolean)
    ' Do something when a new document is created
End Sub

Private Sub GlobalMacroStorage_DocumentOpen(ByVal Doc As Document, ByVal FileName As String)
    ' Do something when a new document is opened
End Sub
You can use the Doc parameter as the reference to the document being worked on.

You can place your actual implementation of the event handler right there or at least in the same module, so you don't have to use GMSManager.RunMacro to run a subroutine in another module.

You can also create a new GMS module and put all your code in there. Thus if you want to move your system on another computer, you'll just copy the GMS file and now you will have automatic event handling on that machine as well.

I hope I make sense here
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
NEED HELP ON CORELDRAW SCRIPT. FREE PHOTO CALENDAR IF U CAN! johnlfitz CorelDRAW/Corel DESIGNER VBA 8 06-06-2008 22:59
problem with script or macro. Dr Morpheus CorelDRAW/Corel DESIGNER VBA 1 12-02-2004 13:46
Cropmarks script Peter Macros/Add-ons 0 06-11-2003 03:51
Curve2Line script ! jobar CorelDRAW/Corel DESIGNER VBA 1 14-08-2003 11:40
Corel 10 file conversion script doesn't convert files Kevin CorelDRAW CS 0 13-04-2003 20:28


All times are GMT -5. The time now is 11:49.


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