OnOpenDocument is executed too often

OnOpenDocument is executed too often

Anonymous
Not applicable
449 Views
2 Replies
Message 1 of 3

OnOpenDocument is executed too often

Anonymous
Not applicable

Hello, 

 

I have following sub that is suposed to execute some code once the file has been opened.

 

 Private Sub oAppEvents_OnOpenDocument(DocumentObject As _Document, FullDocumentName As String, BeforeOrAfter As EventTimingEnum, Context As NameValueMap, ByRef HandlingCode As HandlingCodeEnum) Handles oAppEvents.OnOpenDocument
            'fire after document Is Opened
            If BeforeOrAfter = EventTimingEnum.kAfter Then

The problem is that if I open an IAM then it is executed for every single part that makes up the assembly. I would like to have it executed only if the main IAM has finished loading. so basically the actual file I opened.

 

How can this be done?

 

Thanks

0 Likes
Accepted solutions (1)
450 Views
2 Replies
Replies (2)
Message 2 of 3

basnederveen
Advocate
Advocate

Since you know the assembly which is being opened (I assume), you can check if the fullfilename of that assembly matches the one in the onDocumentOpen event.

0 Likes
Message 3 of 3

Frederick_Law
Mentor
Mentor
Accepted solution

OnOpenDocument event will fire when ever a file is open.

You should filter out files you don't need in the handler.

As you can see, OnOpenDocument event is a very costly event to use.  Everytime a file is open, your handler will run even if it just to filter out and quit.  It will slow down file opening.

See if you can get it done without using even.

0 Likes