Message 1 of 2 (184 Views)

the "DocumentBecameCurrent" event

184 Views, 1 Replies
04-14-2006 09:03 AM
In an app I'm working on I'm using the DocumentBecameCurrent event so
that I can update some global data, dialogs & stuff when a user switches
between open documents. This seems to work just fine except in one case.
When Acad first starts it starts with a new, empty drawings (yes, I know
I can change this behavior). If I open an existing drawing without first
closing the "startup" drawing it seems the DocumentBecameCurrent event
fires twice. It appears to fire then the existing drawing is opened, then
in the background Acad switches focus to the startup drawing to close it,
effectively losing focus on the existing drawing, then puts its focus
back on the exising drawing. This causes the the DocumentBecameCurrent
event to fire twice on the same drawing.
Its a bit annoying and has side effects on my global vars.
The easy answer would be to close any "startup" drawing before opening a
new one, but I cant count on that.
Can anyone suggest a way to avoid this double firing?
Thanks, Perry
Active Member
Posts: 10
Registered: ‎01-23-2007
Message 2 of 2 (184 Views)

Re: the "DocumentBecameCurrent" event

02-01-2007 12:30 AM in reply to: *perry
Hi perry,

I know that the answer comes a few months later, but I hope this should help somebody later...
An easy solution, that is often used is to add a flag.

Private Shared flag_docBecameCurrent_done As Boolean = False

Private Sub docBecameCurrent(ByVal o As Object, ByVal e As DocumentCollectionEventArgs)
If (e.Document.IsActive) Then
If Not (flag_docBecameCurrent_done) Then
flag_docBecameCurrent_done = True
flag_docBecameCurrent_done = False
End If
End If
End Sub

IsActive readonly property helps to show only the document that became current, and the flag make your code run only once.

I think that's sufficient to solve the problem.

- David
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.