.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Document close event VB.Net

6 REPLIES 6
Reply
Message 1 of 7
Anonymous
2208 Views, 6 Replies

Document close event VB.Net

I have manged to trap open and current using:-

AddHandler docMan.DocumentCreated, AddressOf dwgOpen
AddHandler docMan.DocumentBecameCurrent, AddressOf dwgBecameCurrent

I need to trap the close and potentially cancel and can i tell if the file
has been changed since it was opened?

I can trap when a document is being destroyed using:-

AddHandler docMan.DocumentToBeDestroyed, AddressOf dwgClose

but it is too late to read from the file or cancel the close.

I tried the following:-

Dim doc As Document =
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument

AddHandler doc.BeginDocumentClose, AddressOf DwgCloseFile



Public Sub DwgCloseFile(ByVal sender As Object, ByVal e As
Autodesk.AutoCAD.ApplicationServices.DocumentBeginCloseEventArgs)

'this is required as acad starts with Drawing1.dwg and these automatically
get closed when a drawing is opened

If sender.isactive Then

'what do i need in here to trap the close and potentially cancel and can i
tell if the file has been changed since it was opened?

end if



End Sub

--
Regards

Dave Preston
6 REPLIES 6
Message 2 of 7
Anonymous
in reply to: Anonymous

The DBMOD system variable tells you if the active document
has been changed since it was opened or last saved.

Unfortunately, by the time the BeginDocumentClose event fires,
the user will already have been prompted to save changes and
if they answer yes, the file will be saved.

Perhaps you can tell us what your ultimate goal is?

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2009
Supporting AutoCAD 2000 through 2009

http://www.acadxtabs.com

Introducing AcadXTabs 2010:
http://www.caddzone.com/acadxtabs/AcadXTabs2010.htm

"Dave Preston" wrote in message news:6006486@discussion.autodesk.com...
I have manged to trap open and current using:-

AddHandler docMan.DocumentCreated, AddressOf dwgOpen
AddHandler docMan.DocumentBecameCurrent, AddressOf dwgBecameCurrent

I need to trap the close and potentially cancel and can i tell if the file
has been changed since it was opened?

I can trap when a document is being destroyed using:-

AddHandler docMan.DocumentToBeDestroyed, AddressOf dwgClose

but it is too late to read from the file or cancel the close.

I tried the following:-

Dim doc As Document =
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument

AddHandler doc.BeginDocumentClose, AddressOf DwgCloseFile



Public Sub DwgCloseFile(ByVal sender As Object, ByVal e As
Autodesk.AutoCAD.ApplicationServices.DocumentBeginCloseEventArgs)

'this is required as acad starts with Drawing1.dwg and these automatically
get closed when a drawing is opened

If sender.isactive Then

'what do i need in here to trap the close and potentially cancel and can i
tell if the file has been changed since it was opened?

end if



End Sub

--
Regards

Dave Preston
Message 3 of 7
Anonymous
in reply to: Anonymous

Thanks for the reply Tony,
We are writing an app that maintains space data in a SQL Server database and
synchronises it with blocks in the cad file - update attributes, potentially
replace / add delete blocks.

Ideally it would be nice to trap the Yes, No Cancel to the close file /
AutoCad command and work interactively with that i.e. If Yes ensure database
changes are saved, No discard them and Cancel cancel the close command.

Is this possible and should I trap the command "Close" rather than the begin
close event? Is there a vb.net sample anywhere of these approaches.

Many thanks

Dave

"Tony Tanzillo" wrote in message
news:6006703@discussion.autodesk.com...
The DBMOD system variable tells you if the active document
has been changed since it was opened or last saved.

Unfortunately, by the time the BeginDocumentClose event fires,
the user will already have been prompted to save changes and
if they answer yes, the file will be saved.

Perhaps you can tell us what your ultimate goal is?

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2009
Supporting AutoCAD 2000 through 2009

http://www.acadxtabs.com

Introducing AcadXTabs 2010:
http://www.caddzone.com/acadxtabs/AcadXTabs2010.htm

"Dave Preston" wrote in message
news:6006486@discussion.autodesk.com...
I have manged to trap open and current using:-

AddHandler docMan.DocumentCreated, AddressOf dwgOpen
AddHandler docMan.DocumentBecameCurrent, AddressOf dwgBecameCurrent

I need to trap the close and potentially cancel and can i tell if the file
has been changed since it was opened?

I can trap when a document is being destroyed using:-

AddHandler docMan.DocumentToBeDestroyed, AddressOf dwgClose

but it is too late to read from the file or cancel the close.

I tried the following:-

Dim doc As Document =
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument

AddHandler doc.BeginDocumentClose, AddressOf DwgCloseFile



Public Sub DwgCloseFile(ByVal sender As Object, ByVal e As
Autodesk.AutoCAD.ApplicationServices.DocumentBeginCloseEventArgs)

'this is required as acad starts with Drawing1.dwg and these automatically
get closed when a drawing is opened

If sender.isactive Then

'what do i need in here to trap the close and potentially cancel and can i
tell if the file has been changed since it was opened?

end if



End Sub

--
Regards

Dave Preston
Message 4 of 7
Anonymous
in reply to: Anonymous

Reconcling changes to external data is something that's typically
done in response to save notifications. Every time a user saves
a file that's been changed since it was opened or last saved, is
where I usually update externally-dependent data.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2009
Supporting AutoCAD 2000 through 2009

http://www.acadxtabs.com

Introducing AcadXTabs 2010:
http://www.caddzone.com/acadxtabs/AcadXTabs2010.htm

"Dave Preston" wrote in message news:6006723@discussion.autodesk.com...
Thanks for the reply Tony,
We are writing an app that maintains space data in a SQL Server database and
synchronises it with blocks in the cad file - update attributes, potentially
replace / add delete blocks.

Ideally it would be nice to trap the Yes, No Cancel to the close file /
AutoCad command and work interactively with that i.e. If Yes ensure database
changes are saved, No discard them and Cancel cancel the close command.

Is this possible and should I trap the command "Close" rather than the begin
close event? Is there a vb.net sample anywhere of these approaches.

Many thanks

Dave

"Tony Tanzillo" wrote in message
news:6006703@discussion.autodesk.com...
The DBMOD system variable tells you if the active document
has been changed since it was opened or last saved.

Unfortunately, by the time the BeginDocumentClose event fires,
the user will already have been prompted to save changes and
if they answer yes, the file will be saved.

Perhaps you can tell us what your ultimate goal is?

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2009
Supporting AutoCAD 2000 through 2009

http://www.acadxtabs.com

Introducing AcadXTabs 2010:
http://www.caddzone.com/acadxtabs/AcadXTabs2010.htm

"Dave Preston" wrote in message
news:6006486@discussion.autodesk.com...
I have manged to trap open and current using:-

AddHandler docMan.DocumentCreated, AddressOf dwgOpen
AddHandler docMan.DocumentBecameCurrent, AddressOf dwgBecameCurrent

I need to trap the close and potentially cancel and can i tell if the file
has been changed since it was opened?

I can trap when a document is being destroyed using:-

AddHandler docMan.DocumentToBeDestroyed, AddressOf dwgClose

but it is too late to read from the file or cancel the close.

I tried the following:-

Dim doc As Document =
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument

AddHandler doc.BeginDocumentClose, AddressOf DwgCloseFile



Public Sub DwgCloseFile(ByVal sender As Object, ByVal e As
Autodesk.AutoCAD.ApplicationServices.DocumentBeginCloseEventArgs)

'this is required as acad starts with Drawing1.dwg and these automatically
get closed when a drawing is opened

If sender.isactive Then

'what do i need in here to trap the close and potentially cancel and can i
tell if the file has been changed since it was opened?

end if



End Sub

--
Regards

Dave Preston
Message 5 of 7
Anonymous
in reply to: Anonymous

Thanks Tony,
So would you trap an event or a command?

"Tony Tanzillo" wrote in message
news:6007016@discussion.autodesk.com...
Reconcling changes to external data is something that's typically
done in response to save notifications. Every time a user saves
a file that's been changed since it was opened or last saved, is
where I usually update externally-dependent data.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2009
Supporting AutoCAD 2000 through 2009

http://www.acadxtabs.com

Introducing AcadXTabs 2010:
http://www.caddzone.com/acadxtabs/AcadXTabs2010.htm

"Dave Preston" wrote in message
news:6006723@discussion.autodesk.com...
Thanks for the reply Tony,
We are writing an app that maintains space data in a SQL Server database and
synchronises it with blocks in the cad file - update attributes, potentially
replace / add delete blocks.

Ideally it would be nice to trap the Yes, No Cancel to the close file /
AutoCad command and work interactively with that i.e. If Yes ensure database
changes are saved, No discard them and Cancel cancel the close command.

Is this possible and should I trap the command "Close" rather than the begin
close event? Is there a vb.net sample anywhere of these approaches.

Many thanks

Dave

"Tony Tanzillo" wrote in message
news:6006703@discussion.autodesk.com...
The DBMOD system variable tells you if the active document
has been changed since it was opened or last saved.

Unfortunately, by the time the BeginDocumentClose event fires,
the user will already have been prompted to save changes and
if they answer yes, the file will be saved.

Perhaps you can tell us what your ultimate goal is?

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2009
Supporting AutoCAD 2000 through 2009

http://www.acadxtabs.com

Introducing AcadXTabs 2010:
http://www.caddzone.com/acadxtabs/AcadXTabs2010.htm

"Dave Preston" wrote in message
news:6006486@discussion.autodesk.com...
I have manged to trap open and current using:-

AddHandler docMan.DocumentCreated, AddressOf dwgOpen
AddHandler docMan.DocumentBecameCurrent, AddressOf dwgBecameCurrent

I need to trap the close and potentially cancel and can i tell if the file
has been changed since it was opened?

I can trap when a document is being destroyed using:-

AddHandler docMan.DocumentToBeDestroyed, AddressOf dwgClose

but it is too late to read from the file or cancel the close.

I tried the following:-

Dim doc As Document =
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument

AddHandler doc.BeginDocumentClose, AddressOf DwgCloseFile



Public Sub DwgCloseFile(ByVal sender As Object, ByVal e As
Autodesk.AutoCAD.ApplicationServices.DocumentBeginCloseEventArgs)

'this is required as acad starts with Drawing1.dwg and these automatically
get closed when a drawing is opened

If sender.isactive Then

'what do i need in here to trap the close and potentially cancel and can i
tell if the file has been changed since it was opened?

end if



End Sub

--
Regards

Dave Preston
Message 6 of 7
Anonymous
in reply to: Anonymous

The Database.SaveComplete event.

You may (or may not) want to filter out auto-saves
(I don't since if AutoCAD crashes, the autosave file
may be used).

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2009
Supporting AutoCAD 2000 through 2009

http://www.acadxtabs.com

Introducing AcadXTabs 2010:
http://www.caddzone.com/acadxtabs/AcadXTabs2010.htm

"Dave Preston" wrote in message news:6007043@discussion.autodesk.com...
Thanks Tony,
So would you trap an event or a command?

"Tony Tanzillo" wrote in message
news:6007016@discussion.autodesk.com...
Reconcling changes to external data is something that's typically
done in response to save notifications. Every time a user saves
a file that's been changed since it was opened or last saved, is
where I usually update externally-dependent data.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2009
Supporting AutoCAD 2000 through 2009

http://www.acadxtabs.com

Introducing AcadXTabs 2010:
http://www.caddzone.com/acadxtabs/AcadXTabs2010.htm

"Dave Preston" wrote in message
news:6006723@discussion.autodesk.com...
Thanks for the reply Tony,
We are writing an app that maintains space data in a SQL Server database and
synchronises it with blocks in the cad file - update attributes, potentially
replace / add delete blocks.

Ideally it would be nice to trap the Yes, No Cancel to the close file /
AutoCad command and work interactively with that i.e. If Yes ensure database
changes are saved, No discard them and Cancel cancel the close command.

Is this possible and should I trap the command "Close" rather than the begin
close event? Is there a vb.net sample anywhere of these approaches.

Many thanks

Dave

"Tony Tanzillo" wrote in message
news:6006703@discussion.autodesk.com...
The DBMOD system variable tells you if the active document
has been changed since it was opened or last saved.

Unfortunately, by the time the BeginDocumentClose event fires,
the user will already have been prompted to save changes and
if they answer yes, the file will be saved.

Perhaps you can tell us what your ultimate goal is?

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2009
Supporting AutoCAD 2000 through 2009

http://www.acadxtabs.com

Introducing AcadXTabs 2010:
http://www.caddzone.com/acadxtabs/AcadXTabs2010.htm

"Dave Preston" wrote in message
news:6006486@discussion.autodesk.com...
I have manged to trap open and current using:-

AddHandler docMan.DocumentCreated, AddressOf dwgOpen
AddHandler docMan.DocumentBecameCurrent, AddressOf dwgBecameCurrent

I need to trap the close and potentially cancel and can i tell if the file
has been changed since it was opened?

I can trap when a document is being destroyed using:-

AddHandler docMan.DocumentToBeDestroyed, AddressOf dwgClose

but it is too late to read from the file or cancel the close.

I tried the following:-

Dim doc As Document =
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument

AddHandler doc.BeginDocumentClose, AddressOf DwgCloseFile



Public Sub DwgCloseFile(ByVal sender As Object, ByVal e As
Autodesk.AutoCAD.ApplicationServices.DocumentBeginCloseEventArgs)

'this is required as acad starts with Drawing1.dwg and these automatically
get closed when a drawing is opened

If sender.isactive Then

'what do i need in here to trap the close and potentially cancel and can i
tell if the file has been changed since it was opened?

end if



End Sub

--
Regards

Dave Preston
Message 7 of 7
Anonymous
in reply to: Anonymous

Thanks for your assistance Tony

"Tony Tanzillo" wrote in message
news:6007237@discussion.autodesk.com...
The Database.SaveComplete event.

You may (or may not) want to filter out auto-saves
(I don't since if AutoCAD crashes, the autosave file
may be used).

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2009
Supporting AutoCAD 2000 through 2009

http://www.acadxtabs.com

Introducing AcadXTabs 2010:
http://www.caddzone.com/acadxtabs/AcadXTabs2010.htm

"Dave Preston" wrote in message
news:6007043@discussion.autodesk.com...
Thanks Tony,
So would you trap an event or a command?

"Tony Tanzillo" wrote in message
news:6007016@discussion.autodesk.com...
Reconcling changes to external data is something that's typically
done in response to save notifications. Every time a user saves
a file that's been changed since it was opened or last saved, is
where I usually update externally-dependent data.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2009
Supporting AutoCAD 2000 through 2009

http://www.acadxtabs.com

Introducing AcadXTabs 2010:
http://www.caddzone.com/acadxtabs/AcadXTabs2010.htm

"Dave Preston" wrote in message
news:6006723@discussion.autodesk.com...
Thanks for the reply Tony,
We are writing an app that maintains space data in a SQL Server database and
synchronises it with blocks in the cad file - update attributes, potentially
replace / add delete blocks.

Ideally it would be nice to trap the Yes, No Cancel to the close file /
AutoCad command and work interactively with that i.e. If Yes ensure database
changes are saved, No discard them and Cancel cancel the close command.

Is this possible and should I trap the command "Close" rather than the begin
close event? Is there a vb.net sample anywhere of these approaches.

Many thanks

Dave

"Tony Tanzillo" wrote in message
news:6006703@discussion.autodesk.com...
The DBMOD system variable tells you if the active document
has been changed since it was opened or last saved.

Unfortunately, by the time the BeginDocumentClose event fires,
the user will already have been prompted to save changes and
if they answer yes, the file will be saved.

Perhaps you can tell us what your ultimate goal is?

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2009
Supporting AutoCAD 2000 through 2009

http://www.acadxtabs.com

Introducing AcadXTabs 2010:
http://www.caddzone.com/acadxtabs/AcadXTabs2010.htm

"Dave Preston" wrote in message
news:6006486@discussion.autodesk.com...
I have manged to trap open and current using:-

AddHandler docMan.DocumentCreated, AddressOf dwgOpen
AddHandler docMan.DocumentBecameCurrent, AddressOf dwgBecameCurrent

I need to trap the close and potentially cancel and can i tell if the file
has been changed since it was opened?

I can trap when a document is being destroyed using:-

AddHandler docMan.DocumentToBeDestroyed, AddressOf dwgClose

but it is too late to read from the file or cancel the close.

I tried the following:-

Dim doc As Document =
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument

AddHandler doc.BeginDocumentClose, AddressOf DwgCloseFile



Public Sub DwgCloseFile(ByVal sender As Object, ByVal e As
Autodesk.AutoCAD.ApplicationServices.DocumentBeginCloseEventArgs)

'this is required as acad starts with Drawing1.dwg and these automatically
get closed when a drawing is opened

If sender.isactive Then

'what do i need in here to trap the close and potentially cancel and can i
tell if the file has been changed since it was opened?

end if



End Sub

--
Regards

Dave Preston

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost